Having trouble. I need a 1 second time base timer. I am attempting to use timer2 on an AVR mega328. So far I think that the timer value for overflow needs to be set to 10800 with the oscillator being a 11.0592Mhz crystal. I am intializing with:
#chip mega328p,16
#option explicit
#define LED PORTB.4
dir LED out
' Add the handler for the interrupt
On Interrupt Timer1Match1 Call InterruptHandler
' Initialise the timer - this is required
' Set prescaler and then start the timer
InitTimer1 Osc, PS_1_1
' Start the timer - this is required
StartTimer 1
TCCR1A = 0x80;
TCCR1B = 0x0C;
OCR1AH = 0xF4;
OCR1AL = 0x23;
'Main routine
Do
Loop
end
'This will be called when the Timer matches
Sub InterruptHandler
LED = !LED
End Sub
Last edit: stan cartwright 2017-12-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Having trouble. I need a 1 second time base timer. I am attempting to use timer2 on an AVR mega328. So far I think that the timer value for overflow needs to be set to 10800 with the oscillator being a 11.0592Mhz crystal. I am intializing with:
InitTimer2 Osc, PS_1024
I have a overflow handler like this:
sub idle_cntr()
end sub
Currently it overflows much too quickly, way faster than 1 second.
look in your installation for a nice set of timer help tools. There is a nice ZIP and one of the tools with help with the parameters.
..\GCB@Syn\GreatCowBasic\Demos\Interrupt_and_Timer_Solutions\Interrupt - Timed examples
these values from timercalculator for 1000ms
Last edit: stan cartwright 2017-12-16
Thanks for the information. I will try these values. I also found the demos, which I has some how overlooked.