{"id":235,"date":"2008-09-15T13:41:27","date_gmt":"2008-09-15T20:41:27","guid":{"rendered":"http:\/\/mightyohm.com\/blog\/?p=235"},"modified":"2015-09-26T11:11:12","modified_gmt":"2015-09-26T18:11:12","slug":"pic-rgb-video-technical-details","status":"publish","type":"post","link":"https:\/\/mightyohm.com\/blog\/2008\/09\/pic-rgb-video-technical-details\/","title":{"rendered":"PIC RGB Video &#8211; Technical Details"},"content":{"rendered":"<p>This page summarizes the technical details behind my <a href=\"http:\/\/mightyohm.com\/blog\/2008\/09\/pic-microcontroller-rgb-video-animations\/\">PIC LCD video project<\/a>.\u00a0 This is a basic tutorial on how to generate analog RGB video using a PIC16F628 microcontroller.<\/p>\n<p><strong>Previous posts on this project:<\/strong><\/p>\n<ul>\n<li><a title=\"Permanent Link to PIC Microcontroller RGB Video - Animations!\" href=\"..\/2008\/09\/pic-microcontroller-rgb-video-animations\/?phpMyAdmin=pfRTB12SN5iI6CmsWzU3sxfiZw0\" rel=\"bookmark\">PIC Microcontroller RGB Video &#8211; Animations!<\/a><\/li>\n<li><a title=\"Permanent Link to Space Invaders!\" href=\"http:\/\/mightyohm.com\/blog\/2008\/09\/space-invaders\/\" rel=\"bookmark\">Space Invaders!<\/a><\/li>\n<li><a title=\"Permanent Link to Generating Analog RGB Video with a PIC Microcontroller\" href=\"..\/2008\/09\/generating-analog-rgb-video-with-a-pic-microcontroller\/?phpMyAdmin=pfRTB12SN5iI6CmsWzU3sxfiZw0\" rel=\"bookmark\">Generating Analog RGB Video with a PIC Microcontroller<\/a><\/li>\n<\/ul>\n<p><strong>Materials needed:<\/strong><\/p>\n<ul>\n<li>An LCD screen like the <a href=\"http:\/\/store.earthlcd.com\/Sharp-4LU4EB-4-B-W-Video-LCD\">Sharp 4L-U4EB<\/a> that accepts a noninterlaced NTSC analog RGB video signal (red\/green\/blue and composite sync all as separate signals).\u00a0 <a href=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/sharp_bw_lcd_manual.pdf\">Poor quality datasheet here.<\/a><\/li>\n<li>(1) <a href=\"http:\/\/www.microchip.com\/wwwproducts\/Devices.aspx?dDocName=en010209\">PIC16F628<\/a> (the <a href=\"http:\/\/www.microchip.com\/wwwproducts\/Devices.aspx?dDocName=en010210\">PIC16F628A<\/a> should be a drop-in replacement.\u00a0 Sorry, I have old PICs lying around.)<\/li>\n<li>A PIC programmer &#8211; I am using a <a href=\"http:\/\/kitsrus.com\/pic.html\">K128<\/a>, but support for it has been discontinued.\u00a0 <a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023805\">Microchip&#8217;s PICkit2 <\/a>is probably your best bet, but I haven&#8217;t used one (yet).<\/li>\n<li><a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en019469&amp;part=SW007002\">MPLAB <\/a>&#8211; the free Microchip IDE, or a compatible PIC assembler<\/li>\n<li>(1) 20MHz crystal (HC-18 or whatever fits your breadboard)<\/li>\n<li>(2) 22pF ceramic capacitors<\/li>\n<li>(3) 470 Ohm 1\/8W resistors<\/li>\n<li>(5) 10K 1\/8W resistors<\/li>\n<li>A 1K potentiometer for brightness control (if needed, my LCD needs one to display anything)<\/li>\n<li>A regulated 5V supply for the PIC, and my LCD needed an 8V supply of its own<\/li>\n<li>Anything else specific to your LCD &#8211; hopefully not much.<\/li>\n<\/ul>\n<p><strong>Firmware:<\/strong><\/p>\n<ul>\n<li>Source code (for use with <a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en019469&amp;part=SW007002\">MPLAB<\/a>) &#8211; <a href=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video7.asm\">lcd_video7.asm<\/a><\/li>\n<li>Hex file &#8211; <a href=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video7.hex\">lcd_video7.hex<\/a><\/li>\n<li>Listing file (<a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en019469&amp;part=SW007002\">MPLAB<\/a> output) &#8211; <a href=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video7.lst\">lcd_video7.lst<\/a><\/li>\n<\/ul>\n<p><strong>Schematic:<\/strong><em><\/em><\/p>\n<p><em>(click to enlarge)<\/em><\/p>\n<p><a href=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"253\" data-permalink=\"https:\/\/mightyohm.com\/blog\/2008\/09\/pic-rgb-video-technical-details\/lcd_video\/\" data-orig-file=\"https:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video.png\" data-orig-size=\"949,772\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"lcd_video schematic\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Schematic&lt;\/p&gt;\n\" data-large-file=\"https:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video.png\" class=\"size-medium wp-image-253 alignnone\" title=\"lcd_video schematic\" src=\"http:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video-300x244.png\" alt=\"Schematic\" width=\"300\" height=\"244\" srcset=\"https:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video-300x244.png 300w, https:\/\/mightyohm.com\/blog\/wp-content\/uploads\/2008\/09\/lcd_video.png 949w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Theory of Operation:<\/strong><\/p>\n<p>The LCD I chose for this project needs four main electrical signals to display video.\u00a0 Three of them carry color information &#8211; red, green, and blue.\u00a0 These three signals can vary from 0V (black) to 0.7V (full brightness).\u00a0 To achieve this, I placed 470 ohm resistors in series with each, as shown in the schematic.\u00a0 The LCD terminates each color signal with a 75 ohm resistor, so the 470 ohm series resistors serve to convert the 5V output of the PIC to a 0.7V max signal for the LCD (using a resistive divider).<\/p>\n<p>The other signal the LCD needs is CSYNC &#8211; an inverse TTL composite sync signal.\u00a0 This signal provides both the horizontal and vertical sync for the LCD.\u00a0 Without these sync signals the image rolls across the display because the LCD doesn&#8217;t know where the image starts or ends.\u00a0 Composite sync seems to be a little bit unusual &#8211; most RGB video signals have separate horizontal and vertical sync signals on separate wires.<\/p>\n<p>A horizontal line of NTSC video is roughly 64\u03bcs long. (\u03bcs = microseconds)\u00a0 At the beginning of each line, CSYNC is held low for 4us, then set high again.\u00a0 The RGB lines are held low during sync and stay low for 8\u03bcs after sync, then set to the desired levels display the desired image on that line.\u00a0 2\u03bcs before the end of the line, RGB are set low again to signal the end of the visible image.\u00a0 At 64\u03bcs, the program loops back to start another line.<\/p>\n<p>You can generate video like this but there would be no vertical hold &#8211; the image would be stable in the horizontal direction because we are generating a horizontal sync but not in the vertical direction.<\/p>\n<p>To create a stable image with vertical sync, you have to create a valid &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Video_field\">field<\/a>&#8221; of video.\u00a0 We&#8217;re creating non-interlaced video, so every field is the same (in contrast with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ntsc\">ordinary interlaced video used in television<\/a>.)\u00a0 A field is composed of 262 horizontal lines.\u00a0 The first line is blank, with CSYNC set low for the entire line.\u00a0 This is the vertical sync.\u00a0 The next 17 lines are called the &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Vertical_blanking_interval\">blanking interval<\/a>&#8221; and occur above the visible image, during these lines horizontal sync is applied but no RGB signals.\u00a0 The next line is the first visible line and consists of both a horizontal sync and RGB signals as discussed earlier.\u00a0 243 lines later, we write one blank line, then loop back and repeat the process all over again.\u00a0 Now we have a valid non-interlaced analog RGB video signal.<\/p>\n<p>The blank lines are mostly due to compatibility with old television sets that needed time to reset the electron gun for the next field.\u00a0 The nice thing is that they give us time to do housekeeping before displaying the next field.\u00a0 For example, during the blanking interval I load the image to display into memory so it can be easily read back later.<\/p>\n<p>The critical thing with regards to timing is that the PIC needs to execute the same number of instructions each time it loops, such that the sync signals always occur at the right time.\u00a0 This is why there are a lot of &#8216;nop&#8217; instructions in my code &#8211; to pad the program execution in the right spots and maintain sync.\u00a0 I started by counting instructions to figure out where to put the &#8216;nop&#8217;s, but by the end of writing the program I was using <a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en019469&amp;part=SW007002\">MPLAB&#8217;s builtin &#8220;Stopwatch&#8221; feature<\/a> instead.<\/p>\n<p>That&#8217;s it for now!\u00a0 If you have any questions, make use of these routines in your own projects, or just find this interesting, please leave a comment!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page summarizes the technical details behind my PIC LCD video project.\u00a0 This is a basic tutorial on how to generate analog RGB video using a PIC16F628 microcontroller. Previous posts on this project: PIC Microcontroller RGB Video &#8211; Animations! Space Invaders! Generating Analog RGB Video with a PIC Microcontroller Materials needed: An LCD screen like &hellip; <a href=\"https:\/\/mightyohm.com\/blog\/2008\/09\/pic-rgb-video-technical-details\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PIC RGB Video &#8211; Technical Details<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[10,443,432],"tags":[46,502,54,44,47,45],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-microcontrollers","category-projects-2","category-tutorials","tag-lcd","tag-microcontrollers","tag-ntsc","tag-pic","tag-rgb","tag-video"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pioCd-3N","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":182,"url":"https:\/\/mightyohm.com\/blog\/2008\/09\/generating-analog-rgb-video-with-a-pic-microcontroller\/","url_meta":{"origin":235,"position":0},"title":"Generating Analog RGB Video with a PIC Microcontroller","author":"Jeff","date":"September 5, 2008","format":false,"excerpt":"Here is a PIC16F628 microcontroller clocked at 20MHz generating an analog RGB video signal with composite sync. This project was inspired by Rickard Gunee's PIC Video Howto which gave me a big headstart in writing the code.\u00a0 Thanks Rickard!\u00a0 I have been wanting to work on this project since reading\u2026","rel":"","context":"In &quot;Microcontrollers&quot;","block_context":{"text":"Microcontrollers","link":"https:\/\/mightyohm.com\/blog\/category\/microcontrollers\/"},"img":{"alt_text":"PIC Microcontroller RGB Video","src":"https:\/\/i0.wp.com\/mightyohm.com\/files\/flickr\/2830216800_9a86edacb1.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":216,"url":"https:\/\/mightyohm.com\/blog\/2008\/09\/pic-microcontroller-rgb-video-animations\/","url_meta":{"origin":235,"position":1},"title":"PIC Microcontroller RGB Video &#8211; Animations!","author":"Jeff","date":"September 10, 2008","format":false,"excerpt":"Update: For those who are interested in seeing how this is done, I have posted schematics and source along with some technical details about this project.\u00a0 Click here to learn more. After two days of straight coding, this is the result - two more aliens and an animation routine that\u2026","rel":"","context":"In &quot;Microcontrollers&quot;","block_context":{"text":"Microcontrollers","link":"https:\/\/mightyohm.com\/blog\/category\/microcontrollers\/"},"img":{"alt_text":"Still images from space invaders animation","src":"https:\/\/i0.wp.com\/mightyohm.com\/files\/flickr\/2845579559_4a81f1af7d_m.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":723,"url":"https:\/\/mightyohm.com\/blog\/2008\/12\/programming-and-customizing-picmicro-microcontrollers-by-myke-predko\/","url_meta":{"origin":235,"position":2},"title":"Programming and Customizing PICmicro Microcontrollers, by Myke Predko","author":"Jeff","date":"December 24, 2008","format":false,"excerpt":"Programming & Customizing PICmicro Microcontrollers, by Myke Predko, is probably the best book out there for someone who is starting out with the PIC series of microcontrollers from Microchip.\u00a0 I used Myke's book as both a tutorial and reference when I created my PIC RGB Video Display.\u00a0 Since then, I\u2026","rel":"","context":"In &quot;Books and Resources&quot;","block_context":{"text":"Books and Resources","link":"https:\/\/mightyohm.com\/blog\/category\/books-and-resources\/"},"img":{"alt_text":"","src":"http:\/\/www.assoc-amazon.com\/e\/ir?t=mightyohm-20&l=as2&o=1&a=0071361723","width":350,"height":200},"classes":[]},{"id":205,"url":"https:\/\/mightyohm.com\/blog\/2008\/09\/space-invaders\/","url_meta":{"origin":235,"position":3},"title":"Space Invaders!","author":"Jeff","date":"September 6, 2008","format":false,"excerpt":"More progress using a PIC microcontroller to generate video.\u00a0 What next?\u00a0 Color is easy.\u00a0 Animations perhaps? PS: If you start looking, these guys are everywhere.","rel":"","context":"In &quot;Microcontrollers&quot;","block_context":{"text":"Microcontrollers","link":"https:\/\/mightyohm.com\/blog\/category\/microcontrollers\/"},"img":{"alt_text":"Space Invaders!!!","src":"https:\/\/i0.wp.com\/mightyohm.com\/files\/flickr\/2835124664_3346a3cd42.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":710,"url":"https:\/\/mightyohm.com\/blog\/2008\/11\/composite-video-with-arduino-daily-duino\/","url_meta":{"origin":235,"position":4},"title":"Composite Video with Arduino (Daily Duino)","author":"Jeff","date":"November 30, 2008","format":false,"excerpt":"Having had some experience generating RGB video signals with the PIC, I have a deep appreciation for the work these guys did in not only generating composite video with an Arduino, but also making a Pong game.\u00a0 The daily duino (need to bookmark that one) has a simpler example based\u2026","rel":"","context":"In &quot;Microcontrollers&quot;","block_context":{"text":"Microcontrollers","link":"https:\/\/mightyohm.com\/blog\/category\/microcontrollers\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dailyduino.com\/wp-content\/uploads\/2008\/11\/dailyduino_tv.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2024,"url":"https:\/\/mightyohm.com\/blog\/2009\/06\/microchip-internet-radio-demonstration-board\/","url_meta":{"origin":235,"position":5},"title":"Microchip Internet Radio Demonstration Board","author":"Jeff","date":"June 23, 2009","format":false,"excerpt":"Microchip Technology, makers of the PIC microcontroller, have released a demo board for the 8-bit PIC18F67J60 that is pre-programmed to function as an internet radio receiver. Anyone familiar with the blog knows that I have a special love for internet streaming radio, so it shouldn't be a surprise that this\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/mightyohm.com\/blog\/category\/electronics\/"},"img":{"alt_text":"Microchip Internet Radio Demonstration Board","src":"https:\/\/i0.wp.com\/mightyohm.com\/blog\/wp-content\/uploads\/2009\/06\/95837-1.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":18,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":5006,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/posts\/235\/revisions\/5006"}],"wp:attachment":[{"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mightyohm.com\/blog\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}