PDA

View Full Version : Turning on & off multiple interrupts



elec_mech
- 28th June 2005, 19:46
Hi all! I'm attempting to use two interrupts - one is on at all times and the other is on only during specific routines. When I first turn on my program and hit a switch, it seems the second interrupt occurs though it should be off. This might be a hardware problem, but I wanted to inquire about turning an interrupt on and off. Here's an example of what I *think* I'm supposed to do:


'PIC18F2525

On Interrupt goto Reset

intcon = %10010000 ' Enable global interrupts and interrupt on RB0

Main:

'Do something here'

'If switch is pushed go to Switched_Pushed

goto Main ' If switch is not pushed, repeat Main routine

Switched_Pushed:

intcon3 = %00001000 ' Enable interrupt on RB1
intcon2.5 = 0 ' Act on falling edge
'Do stuff here, if RB1 goes low, goto Reset

'Do more stuff, if RB1 goes low, goto Reset

goto Main

Disable
Reset:

'Do something here

Resume Over_Here
Enable

Over_Here:

intcon3 = %00000000 ' Turn off interrupt on RB1

goto Main



I notice the PBP manual says you can use On Interrupt more than once. Do I need to add an "On Interrupt goto Reset" before the intcon3 in the Switched_Pushed routine or am I missing something else? Any advice is appreciated.

Darrel Taylor
- 29th June 2005, 21:30
Hi elec_mech,

Changing the Edge Select bit while the interrupts are enabled can cause a False interrupt to be generated.

Turn off the Global Interrupt Enable (INTCON.7) before doing this...

intcon2.5 = 0 ' Act on falling edge

Then clear the INT1IF Flag (INTCON3.0) before enableing GIE again.

HTH,
   Darrel

elec_mech
- 30th June 2005, 15:21
Dave,

Thanks for the info. Unfortunately, I've discovered I'm stuck at step one here. I can't get the INT1 to work. I know the PIC is going low when I push the switch on RB1 to go low, but the PIC seems to ignore it. Any ideas what I'm missing? Here's the sample code I'm working with:


************************************************** *****
trisb = %00000111
portb = %00000000

B2 var byte
i var word
time var word

time = 250


On Interrupt goto Reset

intcon = %10010000 ' Enable GIE and INT0


Main:

for i = 1 to 100
portb.3 = 1
pause time
portb.3 = 0
pause time
button portb.2, 0, 255, 0, B2, 1, Switch
next

goto Main

Switch:

'On Interrupt goto Reset ' Tried this, no luck
intcon3.3 = 1 ' Enable interrupt on RB1


for i = 1 to 20
portb.4 = 1
pause 250
portb.4 = 0
pause 250
next
intcon3.3 = 0 '%00000000 ' Disable INT1
goto Main



Disable
Reset:

portb = %00000000
intcon.1 = 0 ' Clear INT0 flag
intcon3.0 = 0 ' Clear INT1 flag
Resume Over_Here
Enable



Over_Here:
intcon3 = %00000000 ' Turn off INT1 interrupt
button portb.2, 0, 255, 0, B2, 1, Main
pause 10


goto Over_Here
************************************************** ******

INT0 works great.

I've tried adding another On Interrupt (as shown above) linked to the same
handler. I've also tried turning on the INT1 right after the INT0, then turning it off in the Main Routine then back on during the Switch Routine (then off before returning to the Main Routine. I feel I'm missing something fundamental. I'm going to try just turning on INT1 while INT0 is off, but I suspect I'll have the same problem. Any suggestions? Gracias!

elec_mech
- 30th June 2005, 17:50
Okay, I'm an idiot. It turned out to be a hardware problem. Dave, thanks again for the info, everything now seems to work well, at least the demo program.