Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Interrupt problem

 
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: 35

blank.gif
PostPosted: Mon Mar 16, 2015 7:15 pm    Post subject: Interrupt problem Reply with quote

Hi,
I wrote a test program for a pin-change interrupt using a signal generated by an accelerometer sensor LIS331HH.
The program works fine.
Now I ported this bit of code into a bigger program and and the interrupt service routine (ISR) is not jumped to when the interrupt occurs.
Funny thing is if I run the ISR as a subroutine first, the interrupt works flawlessly:

This does not work:

Enable Interrupts
Do
nop
Loop

.......

Int1_launched:
Flight_phase = Launch
Call Beep(5 , 300 , 300)
Return


However this code does :

Gosub Int1_Launched ‘Note that the label of the IRQ is launched first to make the IRQ work.
Enable Interrupts
Do
nop
Loop

.....

Int1_launched:
Flight_phase = Launch
Call Beep(5 , 300 , 300)
Return



The interrupt is defined as follows:

Config Pind.1 = Input
Portd_pin1ctrl = &B00_000_010
Portd_int1mask = &B0000_0010
On Portd_int1 Int1_Launched
Enable Portd_int1 , Lo

Why do I have to run the ISR first in order for the IRQ to work?

Any suggestions appreciated!

(BASCOM-AVR version : 2.0.7.8 )


Last edited by MadAl on Tue Mar 17, 2015 1:19 pm; edited 1 time in total
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 482
Location: Cleveland, OH

usa.gif
PostPosted: Tue Mar 17, 2015 1:31 am    Post subject: Reply with quote

You enable the interrupt on the pin within the interrupt.

When you run the interrupt first, you are initializing the interrupt hardware.

I would suggest moving all of the hardware setup to the main program, before the Do Loop.

JC
Back to top
View user's profile Visit poster's website
MadAl

Bascom Member



Joined: 26 Jul 2010
Posts: 35

blank.gif
PostPosted: Tue Mar 17, 2015 11:15 am    Post subject: Reply with quote

Hi,

thanks for the remark,

below I printed the run down of the INC files (*.BAS file). The definition of the interrupt hardware is in the QuadAnnt_config.inc file which is before the main program in the QuadAnt2015 file.
The Interrupt service routine (ISR) is at the end in the main program. It only sounds a beeper and changes a single variable, no interrupt is enabled within this ISR. So how does this initialize the interrupt hardware?

$include "QuadAnt_Variables.inc" 'Definition of variables and eeprom

$include "QuadAnt_CONFIG.inc" 'Configuration settings

$include "QuadAnt2015.inc" 'Main program

$include "Quadant_menu.inc" 'Menu for communication with Android device

$include "Acceleration.inc" 'Initialisation of accelerometer

thanks,
Allard
Back to top
View user's profile
MadAl

Bascom Member



Joined: 26 Jul 2010
Posts: 35

blank.gif
PostPosted: Tue Mar 17, 2015 10:39 pm    Post subject: Reply with quote

I moved this to the main program:

On Portd_int1 Launched
Enable Portd_int1 , Lo
Enable Interrupts
Config Pind.1 = Input
Portd_pin1ctrl = &B00_011_010
Portd_int1mask = &B0000_0010

this doesn't work, no interrupt is performed.

However this does work and the interrupts are working just fine:

Gosub Launched
On Portd_int1 Launched
Enable Portd_int1 , Lo
Enable Interrupts
Config Pind.1 = Input
Portd_pin1ctrl = &B00_011_010
Portd_int1mask = &B0000_0010
Back to top
View user's profile
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