NTSC composite video VSync

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone!

I am currently developing a small project that consists of generating NTSC composite signals for monochrome video with an atmega328P chip running at 14.7456MHz.
However, I have been having troubles understanding the Vertical Sync timing issues...

Here is my code:

int count = 0;

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

//Horizontal sync
void sync ()
{
    PORTB &= ~(1<<PB3);
    PORTB &= ~(1<<PB2);
    _delay_us(4);
    count++;
}

//Vertical Sync
void Vsync ()
{
    PORTB &= ~(1<<PB3);
    PORTB &= ~(1<<PB2);
    _delay_us(192); //6 long syncs of 30us followed by a 2us sync

}


  while(1) {

//Will draw a gray bar at line 150 with a white background...

if( count != 150 )
{
           PORTB &= ~(1<<PB2);
        _delay_us(8);
        PORTB |= (1<<PB2);
        _delay_us(52);
           sync();

}
if( count == 150 )
{
    PORTB &= ~(1<<PB3);
    _delay_us(8);
    PORTB |= (1<<PB3);
    _delay_us(52);
    sync();
}



      if( count == 262 ) Vsync(); //Even VSync
      if( count == 525){ count = 1;     Vsync(); } //Odd VSync
  }

  return 0;
}

I could draw a gray bar at the middle, but the screen is kinda flickering. The gray bar looks like "blinking". and there is a very flickering black part at the right border of the screen.
Am I generating a correct synchronization with the TV?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are never going to get the required accuracy in C alone - it needs to be cycle accurate - use Asm for the key timing generation

EDIT oh great - this turns out to be a cross-post - locked:

https://www.avrfreaks.net/index.p...

Topic locked