writing on the VGA port

Hello everyone.

Hope this is the correct board to ask about this.

I've got an arduino mega1280, and i'm trying to send data over VGA to my monitor
so i've read, from here and there, that the VGA video resolution is 640x480 - how come screens are usually larger than that, and, for example, the OS(windows) can still access every pixel, when it should send 640x480 pixels only?

well doesn't matter - anyhow, the mega1280 description says that the clock speed of it is 16MHz, and i've read that the speed of the VGA is 25MHz - does that mean i cant use my arduino for that? is there no other way? external clock or something? some PDF i read says i need to switch RGB signals once every 41 nS, isn't that time very tiny? least delay for the arduino is a microsecond, also, i'm using PWM to output the RGB values - which, without any delays, took 15-16 seconds to send all the pixels, that's disappointing isn't it? hope it's not the right way to output my RGB values.
and finally, i'd like to know, the VGA needs HSync and VSync signals, what voltage should they be?

sorry for asking too much - i just can't find enough docs about the VGA
thanks for reading.

Before anything else, a simple question, you want to display an image on a 640x480 screen, right?
If you only use black and white, you get one bit per pixel (1 = black, 0 = white or vice-versa) so 640x480 is 307200 bits which is 38.4Kbytes.
Where are you going to store this image when the biggest Arduino has only 8KB of memory?

Perhaps your best bet is a small PC motherboard, maybe a mini-itx with a Intel Atom, you can get them for 50$-60$, add some memory, a small flashdrive with linux and you are set. If you need to, just use a USB to serial adapter and comunicate with the arduino thru that.

VGA resolution is at most 640x480 pixels; no-one says you have to do that many, not will you be ableto to, but lower resolutions are well within the capabilities of the AVR.

how come screens are usually larger than that, and, for example, the OS(windows) can still access every pixel, when it should send 640x480 pixels only

I'm not sure I understand that sentence.

Where are you going to store this image when the biggest Arduino has only 8KB of memory?

You don't necessarily need to store them anywhere all at the same time - you generate images on the fly.

I edited my post while AWOL was posting his.

i'm using PWM to output the RGB values - which, without any delays, took 15-16 seconds to send all the pixels, that's disappointing isn't it? hope it's not the right way to output my RGB values.

I read this as "I have a 640x480 color image I want to send". shrugh maybe I read wrong.

He could use one of the lower resolutions that carried over to VGA, like CGA with 16 colors.

Anyway, I still say it's easier if he just uses a small PC motherboard as a interface to the screen, no need to bother with anything else, just output what you want to draw thru the serial port (with a program running on the board to draw to the screen of course).

What would work great would to communicate with an ISA or PCI video card - it would have dual port video ram, you write your data into, it takes care of the timing & sycn signals and all that stuff. Then you only need to change the data in the addresses you update.

I used to have a copy of the ISA spec, or its buried somewhere ...

The 16MHz clock is definitely not fast enough to create a video signal.

64048050 is 15 360 000 pixels / second

Ok you still have the horizontal and vertical sync times so that means you have to output the signals much faster than that.

Here is some reading about the signal you need fo VGA VGA Video Signal Generation | PDF | Cathode Ray Tube | Rgb Color Model

But maybe this should be the way to go http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1216734541

The 16MHz clock is definitely not fast enough to create a video signal.

That's an interesting and hugely incorrect misconception.

AWOL:

The 16MHz clock is definitely not fast enough to create a video signal.

That's an interesting and hugely incorrect misconception.

Not if we are talking about VGA video resolution 640x480 lets say 8 bit color. The VGA Standard demands 25MHz pixel clock.

It probably could be done for monochrome with some extra hardware (PISO shift register)

how come screens are usually larger than that, and, for example, the OS(windows) can still access every pixel, when it should send 640x480 pixels only?

Simple most computers nowadays are not VGA, that standard was left in the dirt a long time ago.

I'm curious about this too. What if an external EEPROM/Flash device would be used to store data? It could be copied back to RAM line by line?

Wk

Here's an interesting project that does RGB output.

http://belogic.com/uzebox/hardware.htm

June 2011 Elektor has a great article on this.
Uses a PIC uC, 32K SRAM, and 2 74LS166 FIFO. Accepts Serial data and displays it as 512x480 monocolor output.
Good discussion of timing signals needed & everything.
www.elektor.com/100147
back issues also available free from pololu.com with an order.

I found this code that I'm trying to understand, as the resulting image is really bad. :disappointed_relieved: But it works, I do get a VGA signal. And the fun thing is that by adding Pots to the RGB pins I can select the color of my pixels. (they all look the same, but its still fun)

/* VGA Sync Generator
 * 11/11/08 - dwan : dwanafite@yahoo.fr
 *
 * Based on :
 *  - RG Matrix Example v.2 8/1/08, by BroHogan, from the Arduino Playground
 *  - Simplest universal VGA/PAL terminal, by Ibragimov Maxim Rafikovich, http://www.vga-avr.narod.ru/main.html
 *  - the very useful Timer/Counter/Prescaler Calculator, http://www.et06.dk/atmega_timers/
 *  - Arduino.cc Port Manipulation Tutorial
 *
 * This program outputs pretty accurate VGA syncronization signals. It's using a timer interrupt on timer2, so hopefully you can make other cool things in loop().
 */

// 640 * 480 @ 60Hz - FvSync = 60.3 Hz / FhSync = 31.3 kHz
// HSync : pin 7 Arduino, pin 13 VGA
// VSync : pin 6 Arduino, pin 14 VGA
// Arduino's pin 5 is HIGH when video can be sent, LOW otherwise. I use it to power a transistor. See this wonderful page : http://www.anatekcorp.com/driving.htm
// 1 NOP = 62,5 ns wasted

#define NOP asm("nop")

#define vga_field_line_count 525         // number of VGA lines
#define ISR_FREQ 0x3F                    // Sets the speed of the ISR - LOWER IS FASTER - 62

volatile unsigned int linecount;

void setup()
{
  //Serial.begin(9600);         // set up Serial library at 9600 bps
  DDRD |= B11100000;            // it sets pins 7, 6 and 5 as output without changing the value of pins 0 & 1, which are RX & TX
  //       76543210 <- pin translation

  PORTD |= B11000000;   // sets pins 7 (hSync) and 6 (vSync) HIGH
  //        76543210;
  
  setISRtimer();                        // setup the timer
  startISR();                           // start the timer to toggle shutdown
}

void loop()
{ 
 
}

///////////////////////////// ISR Timer Functions ///////////////////////////
ISR(TIMER2_COMPA_vect)
{
        // Stop video
        // pin 5 LOW
        PORTD &= ~(1 << 5);
        
        // Front porch
        NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP;
        
        // Count number of lines
	if (++linecount == vga_field_line_count)
	{
	linecount = 0;
	}

	// can it be vsync tiem nao ?
	if ((linecount == 10 )||(linecount == 11 ))
	{
		// hsync LOW
		// vsync LOW
		PORTD &= ~(1 << 7);
		PORTD &= ~(1 << 6);
	}
	else    // ,hsync only
	{
		// hsync LOW
		// vsync HIGH
		PORTD &= ~(1 << 7);
		PORTD |= (1 << 6);
	}
	
	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; NOP; NOP; NOP; NOP; NOP;
       
        // nonetheless,
	// hsync HIGH
	PORTD |= (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;
	
	// Start video if we are in a visible area
        if (linecount > 60)//45)
        {
          // pin 5 HIGH
           NOP; NOP; NOP; NOP; NOP;
           #define DRAWLINE PORTD |= (1 << 5); NOP; NOP; PORTD &= ~(1 << 5); NOP; NOP;
           
           DRAWLINE
           DRAWLINE
           DRAWLINE
        }
}

void setISRtimer(){  // setup ISR timer controling toggleing
  TCCR2A = 0x02;                        // WGM22=0 + WGM21=1 + WGM20=0 = Mode2 (CTC)
  TCCR2B = (1 << CS01);                 // /8 prescaler (2MHz)
  TCNT2 = 0;                            // clear counter
  OCR2A = ISR_FREQ;                     // set TOP (divisor) - see #define
}

void startISR(){  // Starts the ISR
  TCNT2 = 0;                            // clear counter (needed here also)
  TIMSK2|=(1<<OCIE2A);                  // set interrupts=enabled (calls ISR(TIMER2_COMPA_vect)
}

void stopISR(){    // Stops the ISR
  TIMSK2&=~(1<<OCIE2A);                  // disable interrupts
}

I just started working on a new VGA RGB Signal code:

http://arduino.cc/forum/index.php/topic,76020.0.html

Wk