I need to blank out a VGA monitor during startup but want to show the user that something is happening.
To achieve this I thought I could use the 16Mhz ATmega8 I already have in the system to display something similar to a progress bar.
I have assigned 3 pins to this. one each for HSync, VSync and video. The video is split to the red and green channels to give a yellow bar.
I need to monitor an IR receiver, I2C and USART at the same time so decided to use the 16 bit Timer1 so I could have some spare cycles between each line. The bar is only displayed on 3 lines so generating the HSync pulse is the only thing that gets done on most Timer1 interrupts.
My problem is that there is more jitter (about 2 to 3 cycles) than I would like. My timer interrupt is this:
TIM1_OVF: ; Timer1 Overflow Handler in S,SREG push A push B
; Prepare timer1 for next timeout in A,TCNT1L ldi B,2 ; Timer1(L) add A,B ; Allow for any delay getting here ldi B,254 ; Timer1(H) out TCNT1H,B out TCNT1L,A
rcall SyncPulseH ; Generate HSync pulse rcall DrawBarLine rcall SonyGet ; Poll IR port
EndTIM1_OVF: pop B pop A out SREG,S reti
The idea was that this would correct for any small delays (a few cycles) before the interrupt is serviced but it doesn't seem to make any difference.
Does anyone have an idea of why the timing correction doesn't appear to do anything or how to improve it? Is this as good as I'm going to get?
I have tried disabling all other interrupts and removing the SonyGet call with no change.
Here is my DrawBarLine routine. Again, I thought that waiting for the timer to reach a particular value would have reduced the jitter to 1 clock cycle.
;****************************************************************** ; Draw loading bar on VGA ;****************************************************************** DrawBarLine: push A
cbi PORTC,VgaVid cpi VgaLineH,1 ; All other lines blank brne BlankLine cpi VgaLineL,80 ; Only show the bar on lines 80~82 brlo BlankLine cpi VgaLineL,83 brsh BlankLine WaitForBarStart: in A,TCNT1L ; Use timer1 to find the start cpi A,4 ; point for the bar brsh WaitForBarStart
mov A,VgaBarCnt sbi PORTC,VgaVid ; Turn on Video (Start of bar) DrawBarLoop: dec A brne DrawBarLoop cbi PORTC,VgaVid ; Turn off Video (End of bar)
BlankLine:
CheckVSync: cbr Flags,(1