Arduino generated VGA (color) signal - Complete!

Hey guys,

By the picture above we can notice that the problem with the black area was solved, and now, the entire screen is filled, so we can print on any corner (640x480 @ 60Hz). The problem was the interrupt function, the time of calling and returning was taking so much time for an ATmega328, I replace the functio call for an "if", checking the timer register all the time. When the timer gets a defined value (31.3KHz), the "if condition" is true and the line is printed. This way the program is not wasting time calling and coming back from the interrupt function.

Another problem was that only CRT monitors were understanding my signal. The problem was the voltage level, now I am using a resistor in series with a diode for R, B and G, forcing my TTL (5V) signal to become 0.7V, as VGA standards says, and any VGA monitor (including LCD and LEDs) can print the signal.

So, everything is solved now, and we can generate color VGA sinal.

Now, I will try to create a library intelligent enough to design shapes and letters, and maybe generate more colors.

Everything using just an Arduino UNO. :))

Here is the code I wrote. Enjoy! We are here to share.

http://pastebin.com/F5Gnewm8

If you are going to try this, you must know this too:

And this:

"VGA industry standard" 640x480 pixel mode

General characteristics

Clock frequency 25.175 MHz
Line frequency 31469 Hz
Field frequency 59.94 Hz

One line

8 pixels front porch
96 pixels horizontal sync
40 pixels back porch
8 pixels left border
640 pixels video
8 pixels right border
---
800 pixels total per line

One field

2 lines front porch
2 lines vertical sync
25 lines back porch
8 lines top border
480 lines video
8 lines bottom border
---
525 lines total per field 

Be aware of turning your RGB signal off when sync pulsing.
And open your eyes for what the compiler is doing (or trying to do) when reading your code. A lot of time is wasted in many situations, and the non-repetitive ones are the most dangerous.

If your signal is not in perfect sync, the monitor will reject your signal.

Use the osciloscope to monitor all this things. 

Good luck and count on me if you need help!

Views: 54321

Comment by Anuj Shah on December 2, 2014 at 9:03am

Hello Marecelo can you please send me the exact pin outs and complete circuit diagram for this circuit? I would really appreciate for the help.

Comment by Marcelo Rodrigues on December 2, 2014 at 1:46pm

Sunny,

I just included a schematic on this post. ;-)

Enjoy!

Comment by Anuj Shah on December 2, 2014 at 1:49pm

Marcelo,

Thank you very much really appreciated :)...

Comment by Muhammad Ali on April 17, 2017 at 7:59am

Hi  Marcelo I am trying to make this code work with Attiny 44a operating @ 20 MHz.

I have modified your code to make it work with the IO pins available in attiny. Unlike Atmega328p attiny has only two timers i.e. timer0 (which is 8 bit ) and timer1 (which is 16 bit). Assuming that timer0 is used for delay functions, I tried to user timer1 for organize the outer loop. The output waveforms on oscilloscope for Hsync and Vsync and for that matter RGB pins are not as expect.

The waveform of the original code shows hsync and vsync frequencies of 60 Hz  and 31.5 kHz.

I have noticed that timer prescaler values for Atmega328 and tiny44 are different. For my case  I have set (CS12,CS11,CS10 to 0,1,0) to set the  prescaling factor to 8. and to obtain the delay of 64 uS (as supposed to be in the original code) I have set the counter value to 80 i.e. 0x50.  

I am pasting in the code here. 

#define NOP asm("nop")
#define BLACK PORTA = 0b00000000;
#define BLUE PORTA = 0b00000001;
#define GREEN PORTA = 0b00000010;
#define CYAN PORTA = 0b00000011;
#define RED PORTA = 0b00000100;
#define MAGENTA PORTA = 0b00000101;
#define YELLOW PORTA = 0b00000110;
#define WHITE PORTA = 0b00000111;

unsigned int linecount = 1;

void setup()
{
DDRA |= 0b10001111; //PA0=Blue,PA1=Green,PA2=RED,PA3= Hsync, PA7= Vsync
PORTA |=0b00000000;
DDRB |= 0b00001000; //PB3 is just a indicator LED
PORTB |=0b00001000;


//set timer
TCCR1A = 0x02; // WGM22=0 + WGM21=1 + WGM20=0 = Mode2 (CTC)
TCCR1B &= ~(1 CS10); //
TCCR1B |= (1 CS11); // Set prescaler
TCCR1B &= ~(1 CS12); //

TCNT1 = 0; // clean counter

TIMSK1 &= ~(1OCIE1A); // set comparison interrupt
TIMSK1 |= (1TOIE1); // set overflow interrupt
}

void loop()
{
noInterrupts();
do{
BLACK;
if (TCNT1 > 0x50){

delayMicroseconds(1);
NOP;NOP;NOP;NOP;

TCNT1 = 0x00;

// #### HSYNC ###
PORTA &= ~(1 3);
if (++linecount >= 525){ //525 lines
linecount = 1;
}
PORTA |= (1 3);

// ### VSYNC ###
if ((linecount == 1)||(linecount == 2)){
PORTA &= ~(1 7);
} else {
PORTA |= (1 7);

NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
NOP;NOP;NOP;NOP;NOP;

if ((linecount >= 9) && (linecount <= 489)){

WHITE;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
BLACK;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
BLUE;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
GREEN;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
CYAN;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
RED;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
MAGENTA;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
YELLOW;
delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
BLACK;
NOP;NOP;NOP;NOP;
}

}

}

PORTB^=(12) ; // just to check if the board is alive!
}while(1);

}

I would really appreciate if you could take a look at this code and advise me further.

Comment by Marcelo Rodrigues on April 17, 2017 at 11:28am

"The output waveforms on oscilloscope for Hsync and Vsync and for that matter RGB pins are not as expect.

The waveform of the original code shows hsync and vsync frequencies of 60 Hz  and 31.5 kHz."

Muhammad,

For this code to work it is REALLY important the frequencies are correct. My advice is to play with the timers as long as you need until you get the precise frequencies.

With hsync and vsync you will already be able to see the monitor working properly (no error messages on the screen, just a black image).

After that you can create one dot on the screen and improve your code step by step. Avoid to use my whole code until you are dominating the rough part.

Good luck!

Comment by Muhammad Ali on April 18, 2017 at 7:24am

Thanks for the advice. I will persist with the code till I get it done.

thanks once again.

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Igor Golov is now a member of GarageLab (arduino, electronics, robotics, hacking)
Thursday
Marco is now a member of GarageLab (arduino, electronics, robotics, hacking)
Monday
Muhammad Ali commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
"Thanks for the advice. I will persist with the code till I get it done. thanks once again."
Apr 18
Marcelo Rodrigues commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
""The output waveforms on oscilloscope for Hsync and Vsync and for that matter RGB pins are not…"
Apr 17
Muhammad Ali commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
"Hi  Marcelo I am trying to make this code work with Attiny 44a operating @ 20 MHz. I have…"
Apr 17
Profile IconReal NOiseux, Muhammad Ali, bob v and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Apr 17
baiqian is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 10
Profile IconDavide and Almas Amandossov joined GarageLab (arduino, electronics, robotics, hacking)
Apr 6
Profile Iconvamoalrenga and John Ferrell joined GarageLab (arduino, electronics, robotics, hacking)
Apr 3
Marcelo Rodrigues replied to FiniousFingers's discussion New to group
"Yes, please share your progress here. Thanks and good"
Mar 27
FiniousFingers replied to FiniousFingers's discussion New to group
"Thanks, good to know someone is out there. I will be…"
Mar 27
Edward Evans replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Have you moved forward with any action?  I would be interested in discussing your…"
Mar 27
Marcelo Rodrigues replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Ed, No, they didn't deliver yet.  :( Good luck for us all."
Mar 23
Profile IconWesenachin Asfaw and Muhammad Basil joined GarageLab (arduino, electronics, robotics, hacking)
Mar 23
Marcelo Rodrigues replied to FiniousFingers's discussion New to group
"Hey man! A good point to start is reading basic tutorials on Arduino coding and wiring. Then, you…"
Mar 23
FiniousFingers posted a discussion

New to group

Couple quick things,I am just starting to learn, or wanting to learn, how to use the Arduino UNO…See More
Mar 23
Profile IconDan Urbauer, Bjorn and Jiaming Zhao joined GarageLab (arduino, electronics, robotics, hacking)
Mar 22
FiniousFingers is now a member of GarageLab (arduino, electronics, robotics, hacking)
Mar 20
Erva updated their profile
Mar 16
Erva and Mrs. Priscilla Bonneval are now friends
Mar 16

© 2017   Created by Marcelo Rodrigues.   Powered by

Badges  |  Report an Issue  |  Terms of Service