I have made the source code available on Github.
![]() |
Daft Punk from Tron Legacy |
![]() |
VGA Controller on a Breadboard |
![]() | ||
The AVR Logo |
The next step was to decide on a colour gamut. I needed something that I could write out to the I/O pins very quickly and also be memory efficient. I decided to implement RGB222. This is a simple and small colour gamut with 2^6 = 64 colours. There are two bits for each Red, Green and Blue. The two remaining two bits are unused.
![]() |
RGB222 Byte |
I implemented the palette in Gimp so that I could index images and apply dithering. You can download a copy of the palette below if you would like to experiment with it. This palette is compatible with both Gimp and Inkscape.
RGB222.gpl
Designing the Framebuffer
I have 16kB of RAM to work with and I must keep the aspect ratio of the frame buffer 4:3. It would also be beneficial if horizontal could divide into 640 and vertical could divide into 480 evenly. I crunched some numbers using one of my favourite tools, WolframAlpha, and decided that 128x96 was my best bet. A frame buffer of this size requires 12288 bytes of RAM. It allows 5 instructions for drawing each pixel and requires that each line be drawn 5 times.
To make this RGB222 color space come to life I had to design a DAC. I decided to use a weighted R/R2 DAC, taking into account the input impedance of the monitor (75 ohms). I end up with a circuit as shown below. There are three of these circuits connected to one of the 8-bit ports on the microcontroller.
![]() | ||
One of the 3 DACs |
![]() |
DAC Assembled on a Breadboard |
Implementation in Software
The entire VGA generation and buffer is implemented in assembly under the GNU toolchain. I decided to implement the active video region as an unrolled loop that I include in the main assembly file. It takes 2 instructions to write one pixel to the display and 2 padding nops. The ld takes 2 cycles which comes to a total of 5 cycles.
ld r18, Z+
out r18
nop
nop
The H_SYNC and V_SYNC are a series of software delays. The current version has no provision for dynamic graphics. This is something that I will be working on in the future.
Displaying an Image
I have written a crude program in C# to convert an indexed image to the binary format accepted by the microcontroller.
The first thing the CPU does after it boots is copy image data into the frame buffer memory. After this, the standard VGA generation routines continuously draw this frame out on the VGA lines.
Next Steps
My next goal is to implement a command set that is active during the vertical blanking interval. I would like to allow another microcontroller to send commands to this VGA controller such as set pixel. This would allow for dynamic graphics to be generated.
Why not put both extra bits into the G channel? This gives you enhanced color depth where the human eye will most notice it but still allows your matched greys.
ReplyDeleteI had considered the fact that the eye is most sensitive to green light, but didn't consider assigning both bits to the green channel.
DeleteGood idea!
A nice solution I saw before was instead of using them as colours use them as brightness; so the 4 possible values give 4 levels of brightness for each of the 64 combinations of colours -- however I think it complicates the DAC layout somewhat.
ReplyDeleteInteresting project; I think VGA is a lot nicer than composite; You must have seen the uzebox project by now?
This comment has been removed by the author.
ReplyDeletenice lazarus64 vga demo.
ReplyDeleteI make an assembler project using avrstudio 5
ReplyDeleteand included all the project files
when I build the Project
it give me that error
invalid entry file , value cannot be null
Any ideas ?
Thanks
Hi Mohammad,
DeleteI am unsure of why you would get this error. You I suspect that the error message you have posted is truncated. Is there any indication of line number that this error occurred on?
I know that AVR Studio will include its' own header file (for register definitions). You may need to remove this.
I have no idea what assembler you are using. I assume something AVR Studio (which is potentially GNU). The code I have posted assembles on my system (Arch Linux).
DeleteYou could use remainding 2 bits left from RGB222 (RRGGBBxx) as intensity bits (RRGGBBII), similar trick to what old ZX Spectrum did. That way you get 256 colors with correct grays as you would expect. Implementation is quite simple, and can be seen for example here: http://www.lucidscience.com/pro-vga%20video%20generator-2.aspx
ReplyDeleteHi,
ReplyDeleteyour project inspred me to do something similar on a beefier hardware (Beaglebone Black). Thanks for sharing the idea!
http://mujweb.cz/molej/arvid/
Hii can you have all project in atmel studio? because i don't know about linux and it command. if you have project in atmel studio than please send it to my following email address.
ReplyDeleteplz provide me the pin description and also the the list of components require.
ReplyDeletethank you
Choosing the best video converter software is like choosing the best car, there is no "one size fits all" video converter. Before purchasing one, you need to know what files you have and which device you want them converted to. For example, if you want your video files put on your Apple iPhone 3G s or iPod Touch, you need to convert the video to MP4; if you received video made on Mac, you probably Youtube to Mp3 Converter to choose a converter program that is able to convert MOV to other windows media support, like WMV.
ReplyDeleteA printed circuit board is an electronic unit that is used to connect electrical elements into various appliances and machinery. PCB reverse engineering You need to also be sure that the concerned company will do what it takes to test the PCB before the actual production begins.
ReplyDelete