120 likes | 324 Views
Joe Crop. AVR Video Generation. NTSC Composite Video Signal. NTSC Composite Video Signal. The Video Circuit. V&H Sync. ISR(TIMER1_COMPA_vect) { PORTD = syncON; //start the Horizontal sync pulse LineCount++ ; //update the current scanline number
E N D
Joe Crop AVR Video Generation
V&H Sync ISR(TIMER1_COMPA_vect) { PORTD = syncON; //start the Horizontal sync pulse LineCount++ ; //update the current scanline number if (LineCount==248) //begin inverted (Vertical) sync after line 247 { syncON = 0b00100000; syncOFF = 0; } if (LineCount==251) //back to regular sync after line 250 { syncON = 0; syncOFF = 0b00100000; } if (LineCount==263) //start new frame after line 262 { LineCount = 1; } _delay_us(2.65); //extra delay for 16MHz CPU PORTD = syncOFF; //end sync pulse }
avr/sleep.h CodeVision Compiler MCUCR = 0b00100000; #asm ("sleep"); AVR-GCC #include <avr/sleep.h> sleep_enable(); sleep_CPU(); Other Functions //idle, power-down, ADC noise reduction, standby... set_sleep_mode(<mode>); sleep_mode(); // go to sleep with selected mode. sleep_disable(); // disable sleep mode.
Pixel Manipulation char screen[800]; Line 1: Line 2: . . Line 100: //left-shift 3 would be individual lines // <<2 means line-double the pixels //The 0xfff8 truncates the odd line bit //ScreenTop=30, ScreenBot=230 i=(LineCount-ScreenTop)<<2 & 0xfff8;
Predicting the Compiler CodeVision Compiler PORTD.6 = v1 & 0b10000000; PORTD.6 = v1 & 0b01000000; PORTD.6 = v1 & 0b00100000; PORTD.6 = v1 & 0b00010000; PORTD.6 = v1 & 0b00001000; PORTD.6 = v1 & 0b00000100; PORTD.6 = v1 & 0b00000010; PORTD.6 = v1 & 0b00000001; AVR-GCC If((v1 & 0b10000000) != 0) { PORTD |= 0x40; } else { PORTD &= 0xBF; asm("nop"::); } asm("nop"::); asm("nop"::); asm("nop"::); What do you expect the assembly to be?
Predicting the Compiler • Unfortunately we can’t trust GCC to compile this bit-for-bit. • GCC adds random “bookkeeping” code that ruins the timing. • Proposed Solution: • Put video variables in registers • register uint8_t v1 asm(”r6"); • Write video generation code in assembly.
References / Sources • Stanford University EE281 Lab 4: "TV Paint” • http://www.stanford.edu/class/ee281/handouts/lab4.pdf • Atmel Applications Journal: AVR video generator with an AVR Mega163 • http://www.atmel.com/dyn/resources/prod_documents/mega163_3_04.pdf • Cornell University EE476: "Video Generation with AVR Microntrollers” • http://instruct1.cit.cornell.edu/courses/ee476/video/index.html
Demonstration My Version of Wii Fit