diff --git a/main.S b/main.S index e6b5978..cf5a9a0 100644 --- a/main.S +++ b/main.S @@ -39,20 +39,30 @@ main_asm: .global int_horizontal_sync_s int_horizontal_sync_s: push r31 + push r30 ; load timer to trigger isr at the beginning of the visible scanline + ; reset counter to 0 ldi r31, 0 - sts TCNT0, r31 - lds r31, hpos ; set counter TOP - sts OCR0A, r31 + sts TCNT1H, r31 + sts TCNT1L, r31 - ldi r31, 0x7 ; clear any pending interrupt - sts TIFR0, r31 + ; set counter TOP (MSB first!) + lds r31, hpos + 1 + lds r30, hpos + sts OCR1AH, r31 + sts OCR1AL, r30 - lds r31, TIMSK0 - ori r31, 0x02 ; mask enable interrupt timer A - sts TIMSK0, r31 + ; clear any pending interrupt + ldi r31, 0x7 + sts TIFR1, r31 + ; enable interrupt timer A + lds r31, TIMSK1 + ori r31, 0x02 + sts TIMSK1, r31 + + pop r30 pop r31 ret @@ -67,9 +77,9 @@ int_timer_0: push r25 ; turn off interrupt - lds r31, TIMSK0 + lds r31, TIMSK1 andi r31, 0xfd ; mask disable interrupt timer A - sts TIMSK0, r31 + sts TIMSK1, r31 lds r31, show_image cpi r31, 0x1 diff --git a/main.c b/main.c index a07a29e..f430d8c 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ volatile uint8_t image = 0xff; // horizontal and vertical position of bouncing logo volatile uint8_t vpos = 0; -volatile uint8_t hpos = 0; +volatile uint16_t hpos = 0; volatile int8_t vinc = +1; volatile int8_t hinc = +1; @@ -36,7 +36,7 @@ ISR(INT0_vect) { vinc = -1; if (hpos == HORIZONTAL_OFFSET) hinc = +1; - if (hpos == 255 - 40) + if (hpos == 1024 - 80) hinc = -1; int_vertical_sync_s(); @@ -53,7 +53,7 @@ ISR(INT1_vect) { int_horizontal_sync_s(); } -ISR(TIMER0_COMPA_vect, ISR_NAKED) { +ISR(TIMER1_COMPA_vect, ISR_NAKED) { // back porch timer interrupt asm("jmp int_timer_0"); } @@ -73,9 +73,13 @@ int main() { EICRA = 0x0a; // external interrupt 0 and 1, falling edge EIMSK = 0x03; // external interrupt 0 and 1, mask enable - TCCR0A = 0x02; // don't connect output pins to timer, CTC[1:0] mode + TCCR1A = 0x00; // don't connect output pins to timer, CTC[1:0] mode + TCCR1B = 0x09; // CTC[3:2] mode, no prescaler +#if 0 + TCCR0A = 0x02; // don't connect output pins to timer, CTC[1:0] mode TCCR0B = 0x01; // CTC[2] mode, no prescaler +#endif main_asm(); }