View previous topic :: View next topic |
Author |
Message |
MadAl
Joined: 26 Jul 2010 Posts: 48
|
Posted: Mon Dec 21, 2020 5:49 pm Post subject: Timer1 interrupt won't fire |
|
|
Hi,
the following bit of code wont fire the interrup (ISR). What could be wrong?
Note that the timer is running as I can get a pulse on the OC1A port. Also the led works if I enable it in the DO-LOOP
Code: |
$regfile = "m328pdef.dat" ' specify the used micro
$crystal = 11059200
$baud = 115200
$hwstack = 256
$swstack = 256
$framesize = 256
Led_red Alias Portc.5
Config Led_red = Output
Reset Led_red
Config Timer1 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
Compare1a = 5399
On Compare1a Timer1_isr Nosave
Enable Compare1a
Do
Waitms 500
' Toggle Led_red
Loop
Timer1_isr:
Toggle Led_red
Return
End |
thanks for a hint to get this going.
(BASCOM-AVR version : 2.0.8.3 ) |
|
Back to top |
|
|
TW
Joined: 05 Nov 2009 Posts: 5
|
Posted: Mon Dec 21, 2020 6:11 pm Post subject: |
|
|
Hi,
Enable interrupts?
Thomas |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Mon Dec 21, 2020 6:25 pm Post subject: |
|
|
...and don't use nosave in on interrupt statement whem using isr like you do. |
|
Back to top |
|
|
MadAl
Joined: 26 Jul 2010 Posts: 48
|
Posted: Mon Dec 21, 2020 6:32 pm Post subject: |
|
|
Thanks,
I removed 'nosave' and the interrupt was already enabled by 'enable compare1a' . I tried replacing it by 'enable interrupts'.
No result..... |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Dec 21, 2020 6:45 pm Post subject: |
|
|
MadAl wrote: | the interrupt was already enabled by 'enable compare1a' . I tried replacing it by 'enable interrupts'. |
No replacing, you need them both. |
|
Back to top |
|
|
MadAl
Joined: 26 Jul 2010 Posts: 48
|
Posted: Mon Dec 21, 2020 6:49 pm Post subject: |
|
|
OK, so both 'enable compare1a' as well as 'enable interrupts' must be used I just found out. I was under the presumption that 'enable compare1a' would enable that particular interrupt. Not so.
Thanks for pointing that out! |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Dec 21, 2020 6:56 pm Post subject: |
|
|
MadAl wrote: | 'enable compare1a' would enable that particular interrupt. Not so. |
Right so. The particular interrupt needs to be enabled and 'Enable Interrupts" additionally.
The latter is a global switch, affects the I-flag in the processor's status register, called SReg. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue Dec 29, 2020 1:37 pm Post subject: |
|
|
you best read the help topic about ENABLE and also ON INTERRUPT
you could say that the individual hardware interrupt on/off enable/disable switches form an AND gate with SREG-I , the master switch.
also note that the interrupt flags will be set regardless if an interrupt is enabled/disabled. the enable will only cause the call of the sub routine. _________________ Mark |
|
Back to top |
|
|
|