Hi,
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);
_delay_us(4);
count ++;
}
//Paints one line
void paintLine( int color )
{
if( color == 0 ) //BLACK
{
PORTB |= (1<<PB2); //LOW
_delay_us(60);
PORTB &= ~(1<<PB2); //HIGH
_delay_us(0);
}
else if ( color == 1 ) //WHITE
{
PORTB &= ~(1<<PB2); //LOW
_delay_us(16);
PORTB |= (1<<PB2); //HIGH
_delay_us(44);
}
else if( color == 2 )
{
_delay_us(8);
PORTB &= ~(1<<PB3); //LOW
PORTB |= (1<<PB2); //HIGH
_delay_us(51);
PORTB |= (1<<PB3); //HIGH
PORTB &= (1<PB2);
_delay_us(1);
}
}
int main() {
//PB3 AND PB2 AS OUTPUTS
DDRB |= (1<<PB3);
DDRB |= (1<<PB2);
while(1) {
if( count <= 400 )
{
paintLine(0);
paintLine(2);
sync();
}
else sync();
}
if (count >= 525) count = 1;
}
return 0;
}