Generating composite video signals

I am using an atmega328P running at 14MHZ.

I've been reading tutorials about how composite video signals works. For exmaple rickard's tut.
And I've been trying to generate something by myself. I got a white screen (I am not really sure what I am doing though). The white screen works fine though.
However, when I try to "paint" an specific line on the TV with other color, black for example, I get a flickering image, and it is not what I want.

I have a variable incrementing by one every 64us (that's one line, after the 4us sync signal, the next line should be painted and so on....). When that variable reaches 525, it will be reset to 0 (since the TV has 525 lines). It is not working for me though. here is the C code (not using the arduino code right now):

//PORTB |= ([b]PIN NUMBER[/b]); makes a pin HIGH
//PORTB &= ~[b](pin number[/b]); makes a pin LOW
int count = 1;

//(4us pulse) Sync with tv (like the enter key)
void sync()
        PORTB &= ~(1<<PB3); //SYNC : 0V (low)
        PORTB &= ~(1<PB2);

      count ++;


//Paints one line
void paintLine( int color )
    if( color == 0 ) //BLACK
       PORTB |= (1<<PB2); //LOW
      PORTB &= ~(1<<PB2); //HIGH


    else if ( color == 1 ) //WHITE
       PORTB &= ~(1<<PB2); //LOW
      PORTB |= (1<<PB2); //HIGH


    else if( color == 2 )

        PORTB &= ~(1<<PB3); //LOW
        PORTB |= (1<<PB2); //HIGH
      PORTB |= (1<<PB3); //HIGH
      PORTB &= (1<PB2);



int main() {
DDRB |= (1<<PB3); 
DDRB |= (1<<PB2);

  while(1) {

if( count <= 400 )
else sync();

if (count >= 525) count = 1;


  return 0;

It is not working for me though

What isn't working?
Your RS170 signal is missing something?

Your program has a "main", so it isn't really an Arduino problem, is it?

(Could you maybe edit your post to use the code (#) button, please, and get rid of the highlighting?)

Your code doesn't look like it does the vertical sync correctly. The first 6 lines and the last 3 have a different sync pattern to the others. Look at the diagram condemned posted at (but remember NTSC is 262 lines instead of 312)

Also you are sending all 525 lines at once, that isn't right, you should only be sending 262 lines each frame. 525 lines requires interlacing which has even more complicated sync timing. Unless you understand interlacing it's best to just do 262 lines.

I've played around with this myself. You will run into allot of timing issues on this. You will also be limited to black and white. Adding more colors is outside the ability of the arduino.

Here is my code for it.

The most successful working of composite for the arduino has been done here. Your better off with a TellyMate shield to handle it all.

He outlines how to use the arduino itself as the TellyMate in this thread.

Thanks for the replies. I will make sure to add the VSync and let you know my progress. Just some few questions...

The Vsync should be a 64us signal? Is the horizontal sync be 64us too?
Shouldn't be the whole signal for each line a 64us signal with the VSync, blanking, and display? :slight_smile:

Thank you!


Here's a fairly simple description of the signals: