PDA

View Full Version : DT's Instant Interrupts trouble



Tomexx
- 24th November 2008, 18:05
Hi,
I'm very new to the interrupts but I came across Darrel Taylor's instant interrupts and wanted to give it a try. So I tried his program to toggle the led with no problems (thanks Darrel). A pushbutton connected to RB0 (INTE) interrupts main loop and a LED toggles.



CMCON = 7 ' PortA = digital I/O
LED1 VAR PORTA.1

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts

Main:
@ sleep
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN


So now I'm feeling adventurous and wanted to try the interrupts on PortB (RBC_INT). Replaced INT_INT with RBC_INT and moved the switch to B1 but my LED won't toggle anymore when I push the switch (no interrupts)


CMCON = 7 ' PortA = digital I/O
LED1 VAR PORTA.1

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RBC_INT ; enable external (INT) interrupts

Main:
@ sleep
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN


Am I supposed to do something else for RBC_INT?

Thanks,
Tom

Ioannis
- 24th November 2008, 18:18
What chip are you using? Many have only on the 4 upper bits of portb the Interrupt on change feature.

Also check if the option register is set properly or any other register according to the PIC you are using.

Ioannis

Tomexx
- 24th November 2008, 18:53
16F628A. I moved the switch to RB.5, now my led dims but doesn't turn off when push button is pressed.

Ioannis
- 24th November 2008, 19:09
Put an osciloscope on the LED port and you will see why.

You keep on toggling the port while pressing the button and that's why you see the LED dimming.

Other than that your program is OK!

Ioannis

Tomexx
- 24th November 2008, 19:31
It did toggle with my previous setup with switch on B.0 using INT_INT so it should toggle now on B.5 using RBC_INT as well.

When I press the switch I get 2.2V on the led

I think the problem is due to some noise on the lines as my led fill go on/off when I touch the wires. Never had it on B.0, the toggling was smoth with no noise and no dimming.

Tomexx
- 24th November 2008, 20:05
Works now.
I changed the RC values of my switch debouncing and changed the interrupt rutine from:


toggle led1

to


low LED1
pause 50
high led1
pause 50


Now it works providing I don't hold the switch for too long or it triggers another interrupt.



CMCON = 7 ' PortA = digital I/O

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

LED1 VAR PORTA.1

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RBC_INT ; enable external (INT) interrupts

Main:
@ sleep
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
low LED1
pause 50
high led1
pause 50
@ INT_RETURN

Bruce
- 24th November 2008, 20:31
For interrupt-on-change you need to read the port to allow the interrupt flag bit to be
cleared. This takes a snap-shot of the port logic, and triggers the interrupt-on-change
again once the value on the port changes after the last read.

To prevent it from interrupting if you hold a button down too long, then release it, just
use a while/wend to wait for the button to be released. I.E. wait until the switch is
released before exiting your interrupt handler. Then only the change when your switch is
pressed should generate the interrupt.

Tomexx
- 24th November 2008, 20:48
Thanks Bruce that did it!
By the way, your website is very informative.