HELP! Picaxe freezing/locking up when moving to another program slot.

NVHLVNOP

Member
I was playing around with using multiple program slots, on the 40X2, for the first time last night.
I have a program that includes a main menu for me to enter and adjust several settings.
The main menu took up half of the memory on slot 0, so I saved the menu into a different file
and loaded it into slot 1.
My slot 0 program now looks something like this:

DO
IF button1 is pressed, THEN do something written in slot 0
IF button2 is pressed, THEN do something else written in slot 0
IF button3 is pressed, THEN RUN 1 'goes to the main menu
LOOP

My slot 0 program runs great, but when it jumps over to slot 1, the Picaxe locks up on me.
Sometimes it doesn't lock up, sometimes it does. I figured out that it is freezing up on me
because I added the following to the very beginning of the slot 1 program in order to verify:
HIGH led_1
PAUSE 1000
LOW led_1.

When I jump to slot 1 from slot 0, sometimes I'll see the light come on, then go off 1 sec later
and then my main menu will run fine. However, more often than not, I'll see one of the
following results:
1. The LED fails to turn on, but I can no longer operate slot 0. (Picaxe freezes immediately upon Run1 command)
2. The LED turns on, but does not turn off, and I can not operate the slot 0 or 1 program.
(Picaxe freezes immediately after the HIGH led_1 command, or somewhere in the middle of the PAUSE command.

Everytime I've seen the LED turn off, the program seems to run fine without locking up on me.
It seems to want to lock up only during the first few commands of the slot 1 program.

Could it have something to do with the internal timer getting messed up or out of sync? I am not using an
external resonator. I am running the SERVo command in slot 0, which uses the internal timer.

Both slot 0 and 1 programs are downloaded in to the 40X2 using the 40X2 settings. If I combine the two
programs into one long program and redownload it to the chip, everything works great. It seems to be that
the problem comes from jumping from one slot to another.

Any help?

Thanks.
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

I haven't heard of any reports of RUN locking up and I couldn't get it to happen myself. If you suspect it's the SERVO commands you could try commenting them out to see if that changes things.

Another thing to try is changing your IF-THEN-RUN 1 to ..

If Button 3 Pressed Then
SerTxd("Jumping to 1" )
Run 1
SerTxd( "Failed to depart" )
End If

And at the start of Slot 1 add -

SerTxd( "Arrived in Slot 1", CR, LF )

Watching what happens with the Terminal may help prove that what should be happening is, is partly or isn't at all.

Perhaps post your code so we can take a look at it incase there is something which 'jumps out' as being a potential problem.
 

NVHLVNOP

Member
Thanks for the welcome.

I tried adding the HIGH led_1 after the RUN command (where you wrote "failed to depart"), and it never came on. Once it hits the RUN command, it will either go to slot 1 or lock up. It won't go past the RUN command.

Does anyone know how to turn off the SERVO command once it is initiated? I know that once a pin is initiated with the SERVO command, you are supposed to use the SERVOPOS command to make changes to the servo, but I saw no where in the documentation on how to turn the SERVO command off so that it stops pulsing out a signal. Is there a simple command, or perhaps I need to change the pin to an input, and then back to an output? I don't want to get too carried away with this.
 

hippy

Ex-Staff (retired)
Just setting the pin for the servo LOW ( or HIGH ) will stop the servo function on that pin.
 

NVHLVNOP

Member
Ok, so I think I may have solved the problem. Like I said before the picaxe would lock up on me about 7 or 8 times out of ten when I jumped program slots. I had 8 different servo commands running to each portB pin. I thought it may have something to do with the internal timer, so I added the following loop above my RUN 1 command to turn off the servos, as shown here:

FOR counter = 0 to 7
LOW counter 'pins B.0 thru B.7 are also pins 0 thru 7, so I can use the counter var to access the pins
NEXT
RUN 1

Well, this didn't work, but I did see improvement. The picaxe was now locking up on me only about 50% of the time. I still suspected that the internal timer was to blame, so I decided to add a pause and my code looked like the following:

FOR counter = 0 to 7
LOW counter
NEXT
PAUSE 100
RUN 1

Ever since I've done this, the picaxe has not frozen up on me at all. I've only tried it about 10-15 times since I modified the code, but I'm at a 100% success rate since then. Strange things happening with the picaxe!

Also, while I'm in slot 1 and wishing to go back to my main program in slot 0, I decided to replace "RUN 0" with "RESET". There is no need for me to keep the variables and scratchpad data since I have a script at the beginning of slot 0 that loads the eeprom data into the temporary variables and scratchpad. A forced reset has been working great, and it's whole lot more reliable than the RUN command.... for me at least.

I hope at the very least that all this headache I went thru helps someone else in the future.... :)

P.S. Hippy, I tried using the SERTXD command for the first time as you mentioned above, and all I saw on the terminal were funny looking characters. I was expecting to see the same text that I wrote out in the quotation marks. Any ideas? Could it be because I had 8 servos runinng and sharing the internal timer as the serial out pin?
 
Last edited:

BeanieBots

Moderator
This sounds to me very much like a hardware issue.
"servo" comes low on the list of priorities for internal timers and even if it wasn't, there shouldn't be any lock ups as a result of sharing it between commands.
Disabling the servos and seeing an improvement is in my mind the biggest clue to it being hardware related.

Try putting the code back to the original and simply disconnecting the servos so that can be eliminated from the equation. Each servo can easily draw >1A. during startup. Is your power supply good for >8A?

Sounds like you have your terminal baud rate set wrong. Sertxd is 9600 at the default PICAXE clock speed.
 

NVHLVNOP

Member
I did try disconnecting the servos at one point and saw no improvement. I've even tried runnning the program with only 1 servo connected. I am using a 4cell NiMH battery as my power supply, and I have it going thru a 5V low dropout regulator for when the voltage is >5V after a full charge. The servos are under zero load. I haven't hooked anything up to them yet.

Thanks for the info about the baud rate. I think I did try running the terminal at a different setting.
 

hippy

Ex-Staff (retired)
There does seem to be an issue with SERVO when executing RUN commands which we will investigate. The workround would seem to be as you discovered to disable all SERVO channels, PAUSE at least 40ms, then RUN.
 

BeanieBots

Moderator
Although Hippy has explained the root cause, please be aware that if your servos are on the regulated side of the LDO, you will also likely have reset problems. Connect the servos direct to the battery and the PICAXE to the regulator output. Also, make sure you have good decoupling and reservoir capacitors on both sides of the regulator for when the servos start up. Even with no load, they will still pull ~1A as the motor spins up.
 

NVHLVNOP

Member
Thanks. Yes, the servos are powered straight from the battery. The LDO regualtes power to the PicAXE alone. I have caps set in place to make the signals less noisy. Thanks again for all the help and advice.
 
Top