Interrupts causing problems
June 10, 2011
I dislike asking questions - usually it means I didn't RTFM or that my Google skills are sub-par. Or that I'm missing the obvious. But here we are. The following advenure takes place on a Picaxe 28x1 project board (that came with the Solarbotics "Start Here" kit) with a resistor pack replacing the Darlington chip. The Parallax unit is connected to digital i/o pin 3 (though I see the same behavior on other pins). Output pin 2 is connected to an LED (but the same behavior holds for pins 4-7 which drive the motor outputs).
Here is some code:
setint %10000000, %10000000 ; interrupt when pin7 goes high
;This area is "before" the sonar code
low portc 3
high portc 3
low portc 3
let dirsc = %00000000
; This area is "after" the sonar code
high 1 ; LED_1 on
low 1 ; LED_1 off
setint %10000000, %10000000 ; re-activate interrupt
The above code works as intended. Appropriate values are sent to the serial stream, and the LED flashes when the interrupt (a bumper switch) is engaged.
If I add the following LED flash snippet:
"after" the sonar code - everything still works like it's suppose too. However, if I add that snippet "before" the sonar code, the Parallax unit returns "0" every time. If I comment out the interrupt setting, the behavior is as expected and I get proper sonar readings again.
To further confuse things: If I remove the sonar code and put it into a subroutine the behavior changes. Now it doesn't matter whether I put the LED flash code "before" or "after" the gosub call - either way the Parallax returns a "0" reading as long as the interrupt is defined. Removing the interrupt clears the problem and I get the desired behavior.
What am I doing wrong? I've tried changing the interrupt and Parralax i/o pins but get similar behaviors. Where do I go next to troubleshot the problem. I suspect it is software, but perhaps there is a hardware problem I'm not looking for. Any advice or direction is appreciated. If I've left out any critical information, please let me know and I'll answer as best I can.