PDA

View Full Version : First try at DT_INT's, I failed! help please!



MOUNTAIN747
- 5th January 2012, 16:47
Old dogs can learn new tricks, it just takes a little more effort. Can someone please tell me why the RB0 interrupt only works once on this simple routine? This is my first attempt at DT_INT’s. Once I got MPASM set up on MCSP I thought it would be easy. I’m using X1 board with 16F877A and pulsing RB0 with a wire lead. It runs the leds once then will not run again. I’ve tried everything I can think of with no success.


define osc 20
option_reg.6=1 'rising pulse
wsave var byte $70 system
wsave1 var byte $A0 system
wsave2 var byte $120 system
wsave3 var byte $1A0 system
i var byte
LEDS Var PORTD ' Alias PORTD to LEDS
TRISD = %00000000 ' Set PORTD to all output
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:
PAUSE 1
PortD=0
GOTO Main
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1: LEDS = 1 ' First LED on
Pause 500 ' Delay for .5 seconds
For i = 1 To 7 ' Go through For..Next loop 7 times
LEDS = LEDS << 1 ' Shift on LED one to left
Pause 500 ' Delay for .5 seconds
Next i
@ INT_RETURN
end

MOUNTAIN747
- 5th January 2012, 17:19
OK, I have found out that it is returning from the interrupt. However I can not interrupt again for about ten seconds or the interrupt fails. A failure to interrupt forces another ten second delay before I can trigger again. Is there anything I can do to speed this process? On compile the program shows only 255 words long. I don’t understand this time delay before I can re enter the interrupt. Comments please…

Darrel Taylor
- 5th January 2012, 17:33
I’m using X1 board with 16F877A and pulsing RB0 with a wire lead.
That's the problem.

If you are using a wire to +5V, there's nothing to pull it back down.
The pin will hold a charge, and will slowly drain off, allowing it to re-trigger after a few seconds.

If you add a pull-down resistor it should work better.

Or, you can turn on PORTB pull-ups (OPTION_REG.7 = 0), make PORTB.4 LOW so you can use SW1 pushbutton.
Changing to OPTION_REG.6 = 0 will make it trigger on the falling edge (button press) instead of the rising edge (button release).

MOUNTAIN747
- 5th January 2012, 17:35
Thanks Darrel, I'll give it a try!

MOUNTAIN747
- 5th January 2012, 23:34
Yep! works great!

Demon
- 8th January 2012, 22:07
...
Or, you can turn on PORTB pull-ups (OPTION_REG.7 = 0), make PORTB.4 LOW so you can use SW1 pushbutton.
Changing to OPTION_REG.6 = 0 will make it trigger on the falling edge (button press) instead of the rising edge (button release).

This is funny, I did this very exercise yesterday and posted it in the Code Examples. LOL

Robert
:)