Go Down

Topic: Code: VGA RGB Signal (Read 15 times) previous topic - next topic


I uploaded some pictures foe wiring.

Best Regards,

WilliamK Govinda

Thank you so much!  8)



Great thread!

I am looking for a simple ready made solution for generating a 640x480 or 800x600 VGA synch signals from my arduino setup.

I don't need to generate RGB signals, only the sync signals.

I have a Duemilanove board that I am working with.

Can you recommend any programs to start working with (links)?  Anything that can generate a solid synch signal would be OK.  I'm interested in gutting the code if necessary.


BTW - some work that I have been doing with analog VGA synthesis can be found here: http://youtu.be/r1FtvA-pXFg I'm using audio feedback to drive the RGB lines on a VGA signal.  The only thing I'm missing is a good compact and integrated synch generator.


Jan 07, 2012, 04:50 pm Last Edit: Jan 07, 2012, 04:55 pm by Nabe_RMC Reason: 1
Hi pixelform!
Thanks for your comment.
Recently, I enjyoy with RC plane every weekend.
So I have not refined code an not add comment in English yet.
I uploaded the new video and code.
It's currently - temporary version.


I have a Duemilanove board that I am working with.

I have used a Duemilanove board for NTSC or RGB signal generate.

I don't need to generate RGB signals, only the sync signals.

H-sync signal is made with timer1
V-sync signal is made by software ( in interrupt routine )

Can you recommend any programs to start working with (links)?  Anything that can generate a solid synch signal would be OK.  I'm interested in gutting the code if necessary.

Please check following  sources. You can downlod the code from Google code.

defTimer.h  timer1        - set data ( sorry include Japanese comment )
SYS_Ini.cpp : IniTimer( ) - initialize timer1
INT_ICF1.cpp                - interrupt function pointer table
INT_ICF1_RGB_TEST.cpp - display test mode  P_VSYNC_OFF/P_VSYNC_ON <- V-sync generate

BTW - some work that I have been doing with analog VGA synthesis can be found here: http://youtu.be/r1FtvA-pXFg I'm using audio feedback to drive the RGB lines on a VGA signal.  The only thing I'm missing is a good compact and integrated synch generator.

Nice ! and I want to try.

Best regards



I HATE the fact I'm resurrecting an old post... but this project is too damn interest to let it forgotten xD.
Any news on the development? I'd thank if someone had the actual wiring diagrams. I have a Arduino Mega 2560, , but I think I could change things to make it work in this one too,. If someone has anything to help me out, I'd be really thankful.


Feb 10, 2013, 08:08 pm Last Edit: Feb 10, 2013, 08:10 pm by patrik_msc Reason: 1
I'd like to say thanks to Nabe_RMC for sharing his code.

Connection of VGA to Mega 2560 for Nabe_RMC code I found

Code: [Select]

digital pin 32 ---vvv---|       1k
digital pin 33 ---vvv---|       470
                                |______________ VGA pin 1  (RED)

digital pin 34 ---vvv---|       1k
digital pin 35 ---vvv---|       470
                                |_____________ VGA pin 2  (GREEN)

digital pin 36 ---vvv---|       1k
digital pin 37 ---vvv---|       470
                                ______________ VGA pin 3  (RED)

digital pin 53 ---vvv--- >VGA pin 14

PWM  pin 11  ---vvv--- >VGA pin 13

This works without any change of code, however, I stil have sync problem. I just poked file defTimer.h ... By default settings sync values for 640x480VGA aporximately match - video -see on frequency counter http://youtu.be/2NdowIZpLMg , but picture doesn't sync on my two different LCD panels.
default settings are
Code: [Select]
#define CRT_OCR1A_HS    61          /* (1/16MHz)×61 = 3.8125us             */
#define CRT_OCR1A_VS    (508- 61)
#define CRT_ICR1        508  

by setting timers to
Code: [Select]

#define CRT_OCR1A_HS    61     /* (1/16MHz)×61 = 3.8125us             */
#define CRT_OCR1A_VS    (615- 61)
#define CRT_ICR1         615     /* (1/16MHz) × (1017+1) = 31.75us     */

image does sync... is still  little bit blurry, sync signal is out of range, but synced. I found this values experimentaly, and I am aware these are nonsenses - but works. -video and frequency counter readings here http://youtu.be/d7OAr8abiMM (White rectangle in the middle of the screen is LCD's complaint about "OUT OF RANGE"
As a totaly newbie I get Nabe_RMCs notes in code, however i didn't get whole display routine timing ao I am hopeless where to change other display loop parameters. Do you have any suggestions ? Thanks.

Hope I didn't broke rules of this forum, this is my very first post here.


Hi! patrik_msc, I'm Nabe.
I watched your work. Nice try and thanks for using that code.

I was referring to these sites for VGA signal.

I cheked again.But I couldn't find around horizontal frequency - 26kHz.
So, I searched display spec and found thie (Japanese) site.
There seems to be displays horizontal frequency - 24.8kHz, vertical frequency - 56.4Hz.
If this timing, then please change the data and try.

[ defTimer.h ]
Code: [Select]

#define CRT_ICR1    645     /* H-sync:24.8kHz  (1/16MHz) *(644+1) = 40.31us */

[ CRTdef.h ]

Code: [Select]

#define H_NUM_FRM_VGA_A         64
#define H_NUM_TXT_ROW           16
#define V_SYNC_START_VGA_A      0
#define V_SYNC_END_VGA_A        2
#define V_BLANK_VGA_A           ( V_SYNC_END_VGA_A + 28 )
#define H_LINE_FRM_VGA_A        ( V_BLANK_VGA_A + H_NUM_FRM_VGA_A *6 )
#define H_LINE_TXT_END          ( V_BLANK_VGA_A + H_NUM_TXT_ROW *20 )
#define H_LINE_END_VGA_A        440

#define V_SYNC_START_DRAW       0
#define V_SYNC_END_DRAW         2
#define V_BLANK_DRAW            30
#define H_LINE_FRM_DRAW         414
#define H_LINE_END_DRAW         440

And please replace "VGA_LINE_TBL.h" to "VGA_LINE_56400_TBL.h"
I attached the file. So please download and return the file name to "VGA_LINE_TBL.h".
I 'm afraid that front and back porch is too short.
To use your display it may be necessary to reduce the line.
I 'm sorry I don't have 24.8kHz display. So, I cannot try that data.

Last year I had enjoyed another hobby. http://youtu.be/C3oNNU6s63Y  :)
But I came back here.
I decided to write some fuctions for VGAout.
So I made new thread. Please check this.
This week end I will add some functions and up next example.

Code: [Select]
#define CRT_ICR1         615     /* (1/16MHz) × (1017+1) = 31.75us      */
I 'm sorry that comment is wrong.
"(1/16MHz) × (1017+1) = 63.625us" this data is for NTSC signal.
like this

Thanks and enjoy with Arduino!



Hi! patrik_msc,

I changed the data and checked.

[Display on my monitor]
[Horizontal synchronization signal]
[Vertical synchronization signal]

Sync signals are no problem. I think so.
And I think your monitor is not 24.8kH - 56Hz.
Do you have any information about your monitor?

I hope?that you try until what you wnat to do.



I sent you PM yesterday ... there is my LCD datasheet, and video of previous  updated code ... Please check your personal messages in arduino.cc user panel

One of my two monitors is NEC accusync lcd72vm, the second one is DELL 1905FP.

I agree with you, sync itself is not problem, sync signal is generated correctly, but RGB signals doesn't fit to sync in my (dumb) opinion. Former sync frequency was OK.

Thank you for your work


Hi patrik_msc,
I received the information of your monitor.
And I found this manual ( in Japanese ).
The display supports this.( page 18 )
640 x 480 Horizontal frequency - 31.5kHz, Vertical frequency - 60Hz

The horizontal sync signal is made of the timer ( hardware ).
The vertical sync signal (PB_0) is made in software.
Code: [Select]

#define P_VSYNC_ON      asm volatile("sbi 0x05,0"::)    /* PORTB.0          */
#define P_VSYNC_OFF     asm volatile("cbi 0x05,0"::)

There is no difference at ATmega2560 and ATmega328P.
I think so.

You had checked horizontal sync signal yet.
Can you check vertical sync signal out?


You rocks!
I got some blank atmega328PU chips in my drawer... So I will burn duemilanove bootloader and try to make some breadboard ardiuno with them and then test your original unchanged code from code.google.com... , so we can definitely sort that mysterium/compatibility issue out. If there will be some spare time tomorrow I'm gonna to measure frequencies for you too.


Hi patrik_msc,
There is one thing that I want to confirm.
Connection of ground line okay?
I connected in the following.
VGA connector Pin 5,6,7,8,10 ->  Arduino Ground
Oh! the schematic is wrong!
My cable - Pin 9 - Non    :~

Yes! That's my hobby.
If you do not have a deadline,
It's no need to rush?
We will enjoy with Arduino.



Hi Nabe_RMC,
I just hand crafted arduino duemilanove and tested your latest code. It works just right of the box ! I tried to ground/unground pin 9 of VGA connector with duemilanove - no difference at all. Maybe I'll found my test monitor faulty :-)  I uploaded new video on YT here http://www.youtube.com/watch?v=Tfh8p9QqYuo&feature=youtu.be.  You know, as Europeans, we are race of fire by destiny, so we are in the rush all the time.
When I'll find any spare free time, i try to replicate the same result with mega 2560. I really apreciate your development and support. Have a nice day !


Hi patrik_msc,
I watched your new video on Youtube.Thank you for informing the result immediately.I'm glad to know?the good result.
I cheked a manual of MEGA2560 a little.Registers address for port B seems to be the same.So, It will go well about MEGA2560.
Mega2560 has many ports. So, 3bit,3bit,2bit - 256 colors are available. like this.

> You know, as Europeans, we are race of fire by destiny, so we are in the rush all the time.
In Japan, It is also the same. So, we must learn, study more hard.....

If you have any questions or requests, please write this forum or send me E-mail.
I'm so glad to have opportunities to read and to write in English.
I need to learn more English.

I hope you are always happy!


How can i make font size small from 64X64 to 8X12????

Go Up