WKPND_B problem?
Steel
Posts: 313
Using the Third Interrupt example (Who pushed the button first), I tried to make a decision making interrupt.
Unfortunately, when I attempt to assing the WKPND_B register to a variable like they do in the example, I get something completely different.
In the Interrupt, I just assign the WKPND_B register to a variable (WKPENDING).· I then do a FOR/NEXT Loop and send pulses out of RA.0 so that I can read what value the Variable has in it.· Since WKEN_B is disabled except for RB.2,· and I trigger the interrupt by sending a 5V pulse to RB.2, ·I EXPECTED WKPENDING to read "3"...But instead, I am getting a HUGE number (Around 180)·that I captured in the attached OSCope trace.
I can't attach my project code, but here is the only interrupt commands I have:
The Interrupt Vector:
· INTERRUPT
'
ISR_Start:
· ' ISR code here
····
·WKPND_B = WKPENDING
·FOR X = 1 to WKPENDING
··HIGH RA.0
··PAUSE 1
··LOW RA.0
··PAUSE 1
·NEXT
In the beginning of the code:
·'SET UP INTERRUPT CONTROLS TO DETECT·5V PULSE ON RB.2
·WKEN_B = %11111011···················· 'PIN RB.2 Is Enabled
·WKED_B = %00000000
·WKPND_B =%00000000
·
Unfortunately, when I attempt to assing the WKPND_B register to a variable like they do in the example, I get something completely different.
In the Interrupt, I just assign the WKPND_B register to a variable (WKPENDING).· I then do a FOR/NEXT Loop and send pulses out of RA.0 so that I can read what value the Variable has in it.· Since WKEN_B is disabled except for RB.2,· and I trigger the interrupt by sending a 5V pulse to RB.2, ·I EXPECTED WKPENDING to read "3"...But instead, I am getting a HUGE number (Around 180)·that I captured in the attached OSCope trace.
I can't attach my project code, but here is the only interrupt commands I have:
The Interrupt Vector:
· INTERRUPT
'
ISR_Start:
· ' ISR code here
····
·WKPND_B = WKPENDING
·FOR X = 1 to WKPENDING
··HIGH RA.0
··PAUSE 1
··LOW RA.0
··PAUSE 1
·NEXT
In the beginning of the code:
·'SET UP INTERRUPT CONTROLS TO DETECT·5V PULSE ON RB.2
·WKEN_B = %11111011···················· 'PIN RB.2 Is Enabled
·WKED_B = %00000000
·WKPND_B =%00000000
·
Comments
Before doing the "WKPND_B = WKPENDING" instruction you need to set "WKPENDING" to the value you want to swap INTO WKPND_B (usually zero).
But besides that, the bits in the WKPND_B register get set whenever ANY pin on port b changes state, whether it is setup for an interrupt or not. You need to mask out the other bits if you only want to see the one that caused the interrupt. You can just use a "WKPENDING = WKPENDING AND 2" after the "WKPND_B = WKPENDING" line.
Note that this behavour can be very useful if you want to see if a signal changed on a pin without using an interrupt. Just clear the bit in WKPND_B then check it later. If the bit is high then the pin changed.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"The meaning of life, is to give life meaning" Unknown.
·