View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Sun Mar 12, 2017 7:03 pm Post subject: ATMEGA2561 timers? |
|
|
The following generates an interrupt for me and the label SECTICTENTHS is called properly:
Code: |
Config Timer0 = Timer , Prescale = 1024
On OVF0 SECTICTENTHS
Start Timer0 |
However if I use Timer1, 2, 3 or 4 SECTICTENTHS is not called. What am I doing wrong? (and yes, I changed the ON and Start Timer statements accordingly)
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Sun Mar 12, 2017 7:31 pm Post subject: |
|
|
First of all Start Timerx is not needed after Config statement.
Start Timer you must use when timer was stopped by Stop Timer.
Second thing you must understand is "capacity" and their different betwen 8bit and 16bit timers.
Timers 0 and 2 are 8bit timers. So with prescaler 1024 overflow will occur after 1024 x 256 clock ticks (262144 ticks)
Timers 1,3,4 and 5 they are 16bit timers. So with prescaler 1024 overflow occur after 1024 x 65536 clock ticks (67108864 ticks)
This is a huge different dont you think?
If you want to call ISR you should enable it and enable interrupts. I suppose that you have enabled interrupts but do you also enable coresponding OVFx ?
Code: | 'where x is a Timer number
Config Timerx = Timer, Prescale = 1024
On OVFx SECTICTENTHS
Enable OVFx ' <- important
Enable Interrupts |
Not working code should be posted in form that can be compiled. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Sun Mar 12, 2017 7:47 pm Post subject: |
|
|
EDC wrote: | First of all Start Timerx is not needed after Config statement.
Start Timer you must use when timer was stopped by Stop Timer.
Second thing you must understand is "capacity" and their different betwen 8bit and 16bit timers.
Timers 0 and 2 are 8bit timers. So with prescaler 1024 overflow will occur after 1024 x 256 clock ticks (262144 ticks)
Timers 1,3,4 and 5 they are 16bit timers. So with prescaler 1024 overflow occur after 1024 x 65536 clock ticks (67108864 ticks)
This is a huge different dont you think?
If you want to call ISR you should enable it and enable interrupts. I suppose that you have enabled interrupts but do you also enable coresponding OVFx ?
Code: | 'where x is a Timer number
Config Timerx = Timer, Prescale = 1024
On OVFx SECTICTENTHS
Enable OVFx ' <- important
Enable Interrupts |
Not working code should be posted in form that can be compiled. |
Yes, Interrupts are enabled before this statement (I also use a soft clock, which appears to use Timer2 as it is)
So, I as a test, I tried using Timer1, Timer 3, Timer 4 and changed prescale to other values (such as 1). Still no call to SECTICTENTHS no matter what I try. Only Timer0 seems to work
Code: |
$regfile = "m2561def.dat"
$crystal = 16000000
$hwstack = 450
$swstack = 550
$framesize = 345
$Baud = 9600
UCSR0A.U2X = 0
Enable Interrupts
Config Clock = Soft , Gosub = SECTIC
Config Date = MDY , Separator = .
Config Timer1 = Timer , Prescale = 1
On OVF1 SECTICTENTHS |
[/code] |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Sun Mar 12, 2017 9:04 pm Post subject: |
|
|
Oh duh.... I missed that I needed to enable the OVFx interrupt even though I also use the global Enable Interrupts statement.
Now it all works, thanks for your help (but I need to play with timing a bit...)
Code: |
Config Timer4 = Timer , Prescale = 8
On OVF4 SECTICTENTHS
Enable OVF4 |
|
|
Back to top |
|
|
|