Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Timer1 interrupt won't fire

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
MadAl

Bascom Member



Joined: 26 Jul 2010
Posts: 48

blank.gif
PostPosted: Mon Dec 21, 2020 5:49 pm    Post subject: Timer1 interrupt won't fire Reply with quote

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
View user's profile
TW

Bascom Member



Joined: 05 Nov 2009
Posts: 5

poland.gif
PostPosted: Mon Dec 21, 2020 6:11 pm    Post subject: Reply with quote

Hi,

Enable interrupts?

Thomas
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Mon Dec 21, 2020 6:25 pm    Post subject: Reply with quote

...and don't use nosave in on interrupt statement whem using isr like you do.
Back to top
View user's profile
MadAl

Bascom Member



Joined: 26 Jul 2010
Posts: 48

blank.gif
PostPosted: Mon Dec 21, 2020 6:32 pm    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Dec 21, 2020 6:45 pm    Post subject: Reply with quote

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
View user's profile
MadAl

Bascom Member



Joined: 26 Jul 2010
Posts: 48

blank.gif
PostPosted: Mon Dec 21, 2020 6:49 pm    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Dec 21, 2020 6:56 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Dec 29, 2020 1:37 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum