Picaxe resetting or stuck in fatal loop
October 19, 2010
I'm reprogramming Robot Leader, and I'd like to be able to use PWM to pulse his LED eyes. The only problem is, I also have to command a servo to turn his head, and the Picaxe28x1 does not allow you to use PWM while you are using the servo command. They both rely on the same timer.
So I tried turning off the servo whenever I wasn't using it. This seemed like a good idea anyway, as it should reduce some noise and power consumption. The problem is that when I try to turn off the servo by setting the servo pin LOW, my program seems to malfunction.
It passes the syntax check, and the Picaxe simulator runs it without an issue. However, in operation the program never seems to complete the init block and enter the main loop. I don't know if the picaxe is actually constantly resetting itself or what.
Here's the initial code block.
setfreq m4 ' set frequency to 4MHz
Symbol servopin = 0 ' Defines output pin to which the servo turning the head is connected
Symbol soundpin = 3 ' Defines output pin to which a speaker is connected
symbol pirpin = 1 ' Defines analog input pin for signal pin of the Parallax PIR
symbol led1pin = 7 ' Defines the LED pin for one eye
symbol led2pin = 6 ' Defines the LED pin for one eye
symbol right = 80
symbol shakeright = right + 20
symbol center = 150
symbol left = 220
symbol shakeleft = left - 20
symbol pircount = b0 ' count the number of times the PIR is triggered
symbol pirstate = b1 ' store the pirstate (adc value)
symbol flashcount = b3 ' store the number of times to flash the LEDs
symbol remember = w2 ' Temporary variable just used in routines
pause 60000 'wait 60 seconds for PIR to initialize
high led1pin: high led2pin
pircount = 0 ' initialize pircount
pirstate = 0 ' initialize pirstate
flashcount = 0 ' initialize flashcount
The robot just keeps scanning his head through the three servo positions in the init code block. His LED eyes never go on, so the code is never getting pased the pause 60000 statement. Can anyone figure out what is going on?
I checked the Program Editor, and my Picaxe28x1 is running firmware version A.6. So I guess that confirms Ro-Bot-X's findings that multiple versions of the 28x1 have this bug.
I changed my code to deal with the problem. The pause during the init block is only 10 seconds now, and the LEDs will blink on and off each second when this happens. I also eliminated the head movements during the init block. So whenever the servos are shut off, the reset will result in a 10 second blinky light display. That is acceptable.