Friday, March 15, 2013

AVR VGA Generation

I have always wanted to create a VGA generator. It has been a personal goal of mine for some time. Over the past couple of weeks I toyed with the idea and finally decided to implement one. I decided to implement it as a framebuffer to allow for general purpose display rather than application specific display. I implemented my own small colour gamut to be memory and CPU efficient.

I have made the source code available on Github.

Daft Punk from Tron Legacy
VGA Controller on a Breadboard

 The first thing I did was order some new AVRs. I ordered the ATmega1284p because it has 16kB of RAM and 128kB of program memory. My original idea was to clock the MCU at 20MHz. I successfully created an H_SYNC and V_SYNC generator at this clock rate but found it difficult to implement the frame buffer properly. When the chip is clocked at 20MHz, there are only 508 cycles per line of active video. According to the VGA specification the pixel clock is 25.175MHz. I decided to overclock my microcontroller to 25MHz to get 640 clock cycles per line. This makes the code cleaner and allows for a higher resolution frame buffer.

The AVR Logo

Designing the Colour Space

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
You might argue that I should assign bits 6 and 7 to either of the 3 channels, but I decided not to do this. I decided that it would make the creation of grey colours more difficult. This colour space allows for 1 byte per pixel. Since the AVR allows for single-cycle writes to the 0th page of RAM, I can also output this colour in a single instruction. This allows me to hit the theoretical 25MHz pixel clock. Woohoo!

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
 In practice, I decided to use 470 and 220 ohm resistors. This isn't ideal, it applies a skew to the colour space. Ideally these resistors would be low tolerance.

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.

86 comments :

  1. 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.

    ReplyDelete
    Replies
    1. I had considered the fact that the eye is most sensitive to green light, but didn't consider assigning both bits to the green channel.

      Good idea!

      Delete
  2. 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.

    Interesting project; I think VGA is a lot nicer than composite; You must have seen the uzebox project by now?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I make an assembler project using avrstudio 5
    and 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

    ReplyDelete
    Replies
    1. Hi Mohammad,

      I 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.

      Delete
    2. 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).

      Delete
  5. You 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

    ReplyDelete
  6. Hi,
    your project inspred me to do something similar on a beefier hardware (Beaglebone Black). Thanks for sharing the idea!
    http://mujweb.cz/molej/arvid/

    ReplyDelete
  7. 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.

    ReplyDelete
  8. plz provide me the pin description and also the the list of components require.
    thank you

    ReplyDelete
  9. Hello, I am one of the most impressed people in your article. 메이저토토사이트 I'm very curious about how you write such a good article. Are you an expert on this subject? I think so. Thank you again for allowing me to read these posts, and have a nice day today. Thank you.

    ReplyDelete
  10.  Very cool site!! Man .. Beautiful .. Wonderful .. I will bookmark your web site and take the feeds additionally. 먹튀

    ReplyDelete
  11. 토토사이트 I felt amazing reading this and I feel you are absolutely right. Inform me in the event that you are involved in garageband windows, that is my principal competency. I really hope to see you soon, bye for now!

    ReplyDelete
  12. I feel this is among the most vital info for me. And i am happy reading your article. But want to remark on few general things, The web site taste is perfect, the articles is in point of fact great : D. Excellent task, cheers 스포츠토토

    ReplyDelete
  13. 카지노사이트 You can certainly see your expertise in the work you write. The world hopes for even more passionate writers like you who aren’t afraid to say how they believe. Always follow your heart.

    ReplyDelete
  14. I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing 카지노사이트

    ReplyDelete
  15. Thank you for every other informative blog. The place else may I am getting that type of info written in such a perfect means? I’ve a venture that I’m simply now operating on, and I’ve been on the glance out for such information. ufabet1688

    ReplyDelete
  16. Hi! I just want to offer you a huge thumbs up for the great info you have got here on this post. I will be returning to your site for more soon. สมัครยูฟ่าเบท

    ReplyDelete
  17. Excellent blog here! Also your site a lot up fast! What web host are you the usage of? Can I get your affiliate link in your host? I wish my site loaded up as quickly as yours lo google ad copy

    ReplyDelete
  18. This content is simply exciting and creative. I have been deciding on a institutional move and this has helped me with one aspect. ยูฟ่า168

    ReplyDelete
  19. Wonderful web journal. I appreciated perusing your articles. This is really an extraordinary read for me. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome! ยูฟ่า168

    ReplyDelete
  20. Nothing makes your freshly landscaped yard stand out more than a beautiful ​stamped concrete patio. The perfect aesthetic with the mix of resilient material make this a winning combo for any home owner Stamped Concrete Patio

    ReplyDelete
  21. very great eccommerce website for custom packaging boxes try now Lotion Packaging Boxes

    ReplyDelete
  22. I just like the helpful information you supply for your articles.
    I will bookmark your blog and test once more here frequently.
    I’m fairly certain I will learn many new stuff right
    here! Best of luck for the next!
    ufabet

    ReplyDelete
  23. Wow, this is delightful reading.I'm glad I found it and got to read it. Great job on this content. I felt very good. Thanks for the great and unique info.Turkish Visit Visa, All citizens have to complete visa transit Turkey, go through the application process and pay the fee.

    ReplyDelete
  24. 온라인카지노사이트 An extremely motivating story… awesome thanks to you and to every one of the general population who developed this site. Continue going and good fortune.


    ReplyDelete
  25. Very significant Information for us, I have think the representation of this Information is actually superb one 바카라사이트

    ReplyDelete
  26. This article gives the light in which we can observe the reality. This is very nice one and gives in-depth information. Thanks for this nice article
    토토사이트

    ReplyDelete
  27. 토토사이트 Cool stuff you have and you keep overhaul every one of us
    You have done a amazing job with you website

    ReplyDelete
  28. When did it start? The day I started surfing the Internet to read articles related to . I've been fond of seeing various sites related to 먹튀검증 around the world for over 10 years. Among them, I saw your site writing articles related to and I am very satisfied.

    ReplyDelete
  29. Spot on with this write-up, I truly believe that this website needs a lot more attention. I'll probably be back again to read more, thanks for the advice! 야동

    ReplyDelete
  30. I have always disliked the idea because of the costs. Is usually able to answer customer questions. 오피

    ReplyDelete
  31. "What I do not realize is actually how you're no longer actually much more
    smartly-liked than you might be now. You are very intelligent.
    You know thus considerably when it comes
    to this matter, produced me in my view believe it from numerous numerous angles.
    Its like men and women don't seem to be fascinated until it's something to do with Girl gaga!

    Your individual stuffs outstanding. All the time care for it up!"

    마사지

    ReplyDelete
  32. I haven't checked in here for some time since I thought it was getting boring, but the last several posts are good quality so I guess I'll add you back to my everyday blog list. You deserve it my friend 🙂 건전마사지

    ReplyDelete
  33. This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here! Concrete Contractors in Los Altos

    ReplyDelete
  34. When did you start writing articles related to ? To write a post by reinterpreting the 메이저안전놀이터 I used to know is amazing. I want to talk more closely about , can you give me a message?

    ReplyDelete
  35. Nice one, Thanks for sharing valuable information with us.
    Looking forward to learn more from you. 토토

    ReplyDelete
  36. This is one of the best website I have seen in a long time thank you so much, thank you for let me share this website to all my friends. 바카라사이트

    ReplyDelete
  37. The information you are providing that is really good. Thank for making and spending your precious time for this useful information. Thanks again and keep it up.

    온라인카지노

    ReplyDelete
  38. Such an amazing and helpful post. I really really love it.
    카지노사이트

    ReplyDelete
  39. Yes, this is a good post without any doubts. You really do a great job. I inspired by you. So keep it up!! www.alamedaplumbingcontractors.com/

    ReplyDelete
  40. Hello there! Quick question that’s completely off topic.
    Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone.
    I’m trying to find a template or plugin that might
    be able to resolve this issue. If you have any recommendations, please share.
    Thank you!

    website:바카라사이트


    ReplyDelete

  41. Reading your blog is way better than snuggles.
    It is very informative and I bet you are very knowledgeable in this area. 오피월드


    ReplyDelete
  42. hellow~~I was surprised to see your writing. This is a really useful resource~
    I would like to see these materials often~
    I will come here often. Thank you!!!안전놀이터

    ReplyDelete
  43. Nicely researched and presented. Thanks for delivering genuine information먹튀검증

    ReplyDelete
  44. I think this is an informative post and it is very beneficial and knowledgeable.
    Therefore, I would like to thank you for the endeavors that you have made in
    writing this article. All the content is absolutely well-researched. Thank!!토토사이트

    ReplyDelete
  45. I am regular visitor, how are you everybody?
    This article posted at this website is in fact good
    I 토토

    ReplyDelete
  46. Wow the article you give us is amazing, no wonder many people want to read this deck builder

    ReplyDelete
  47. We stumbled over here by a different website and thought I might check things out. I like what I see so now i am following you. Look forward to finding out about your web page again. 안전놀이터모음

    ReplyDelete
  48. Really no matter if someone doesn't be aware of after that its up to other users that they will help, so here it takes place kèo nhà cái.

    ReplyDelete
  49. I blog often and I truly appreciate your content.
    야설
    Feel free to visit my blog :
    야설

    ReplyDelete
  50. This great article has truly peaked my interest.
    일본야동
    Feel free to visit my blog : 일본야동

    ReplyDelete
  51. I’m going to bookmark your site and keep checking for new details about once per week.
    국산야동
    Feel free to visit my blog : 국산야동

    ReplyDelete
  52. I subscribed to your Feed too.
    일본야동
    Feel free to visit my blog : 일본야동

    ReplyDelete
  53. Hi there! This article could not be written much better!
    야설
    Feel free to visit my blog : 야설

    ReplyDelete
  54. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    인터넷경마

    magosuco

    ReplyDelete
  55. Your article has provoked a ton of positive hobby. I can see why since you have made such a decent showing of making it intriguing. 파워볼


    ReplyDelete
  56. In my opinion, the item you posted is perfect for being selected as the best item of the year. You seem to be a genius to combine 먹튀사이트 and . Please think of more new items in the future!

    ReplyDelete
  57. I looked up most of your posts. This post is probably where I think the most useful information was obtained. Thank you for posting. You probably be able to see more. 먹튀보증업체

    ReplyDelete
  58. I think the posts here are good, so I leave a comment. 메이저안전사이트

    ReplyDelete
  59. There are so many good words. It s really helpful and developing on its own. 카지노사이트

    ReplyDelete
  60. Thank you very much for sharing this article. It helped me a lot and made me feel a lot. Please feel free to share such 사설토토사이트

    ReplyDelete
  61. I have recently started a blog, the 안전공원추천 info you provide on this site has helped me greatly. Thanks for all of your time & work.

    ReplyDelete
  62. They were active listeners and provide 토토검증업체 on this site has helped me greatly. Thanks for all of your time & work.

    ReplyDelete
  63. The information you provided is very useful, thank you very much for sharing useful information with us. You can apply for an online Azerbaijan e visa - If you are Planning a Trip to Azerbaijan for tourism, business purposes. You can fill the Azerbaijan evisa application form in less than 5 to 10 minutes.

    ReplyDelete
  64. I found this article on this site while looking for an article on this topic. Reading your post made me feel like an expert in this field. There are several articles on these topics posted on my site. Please visit my website once. 메리트카지노

    ReplyDelete
  65. whoah this weblog is excellent i really like reading your articles.
    토토사이트
    경마사이트
    경마

    ReplyDelete
  66. First of all, thank you for your post. Your posts are neatly organized with the information I want, so there are plenty of resources to reference. I bookmark this site and will find your posts frequently in the future. Thanks again
    카지노사이트
    토토

    ReplyDelete
  67. Please continue this great work and I look forward to more of your awesome blog posts. concrete leveling los angeles

    ReplyDelete
  68. I'm fond of your articles. Thanks for sharing them. Information in the posts give me some pieces of advice. I can solve difficulties by apply them.
    I think of your posts as soon as I'm in trouble. Your pieces of writing are awesome. 파워볼


    ReplyDelete
  69. Thank you The foreign visitors need to apply for kenya online visa. That offers them fast and secure visa services. You also can check the al information regarding to visa here to get in the Kenya

    ReplyDelete
  70. Youre so right. Im there with you. Your weblog is definitely worth a read if anyone comes throughout it. Im lucky I did because now Ive received a whole new view of this. 오공슬롯"


    ReplyDelete
  71. Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks!. cinderblock shelves

    ReplyDelete
  72. Cita previa INEM SEPE. Para tu comodidad, sin que te sea necesario que acudas a la Oficina de Empleo, el SEPE pone a tu disposición en esta página web actualizada continua mente.

    ReplyDelete
  73. This is the perfect post.사설토토사이트 It helped me a lot. If you have time, I hope you come to my site and share your opinions. Have a nice day.


    ReplyDelete
  74. Youre so right. Im there with you. Your weblog is definitely worth a read if anyone comes throughout it good site info for you come 토토사이트 only

    ReplyDelete
  75. I'm fond of your articles. Thanks for sharing them. Information in the posts give me some pieces of advice. I can solve difficulties by apply them. and good totoinfo for you come my web site 사설토토

    ReplyDelete
  76. Very nice article, I enjoyed reading your post, very nice share, and good safe land info for you come my안전놀이터 site only

    ReplyDelete