Picaxe Locks Up

ArnieW

Senior Member
I have a perplexing problem with an 18A.
At seemingly random intervals it appears to freeze or lock up.
- the program downloads ok
- for 98% of the time the code seems to operate ok

What happens is that an output that should be pulsing (on 50ms then off 50ms) will either stay on permanently or off permanently when the problem occurs.

Given the code in the 18A, this cannot happen.
At the same time, the 18A will no longer receive serial in commands from a 40X that continues to operate satisfactorily.

The way to restore the 18A is to reset.

As I want to drive a heating element (3600W) with this control line, it is a serious concern for me.

The power supply is a switchmode PC supply. The 12V line from this is connected to an LM317 with a series resistor on its output to trickle charge (current limited) 4xAA nicads. There are no caps on input or output side of the 317, as I assumed the nicads would be more than enough buffering of spikes etc.

All chips (picaxe and other) have a 100nF cap on supply lines as is recommended. All noisy devices (like buzzer & relays) have diodes connected to prevent back EMF.

My suspicion is that this issue is power supply related because when the nicads are flat or nearly flat the problem is more prevalent.

Any suggestions as to tests or things to try out?

thanks, Arnie
 

andrewpro

New Member
Is the power supply inside a computer already or is it external? If external, they normally require a substantial load (relatively) to maintain regulation. This oculd be causing brownouts or other various voltage problems.
 

hippy

Technical Support
Staff member
The proverbial nightmare. You don't say how often the system latches up, but you do indicate that the problem becomes more frequent when the batteries are nearly flat, so at least you have a mechanism to force a failure which will aid solving the problem - you are after all not interesting in why it works, but why and when it doesn't. Forcing the failure may give much insight into what's happening.

Apart from looking at the actual lines to see if there is noise, spikes, brownouts etc - and not all of us have oscilliscopes - the only other way is perhaps to remove bits of the circuit until the problem goes away, and thus the problem area is identified, which can then point towards probably causes as to why the problem is in that area.

I'm sure this is easier said than done, especially in a control-loop application, and you might have to apply a little ingenuity and lateral thinking. If the system can work without a relay, then take it out, use a LED instead, and then 'fake' the result which would have happened when the relay opened or closed by using a pot instead for a sensor reading. It can get real horriblem, but you need to hunt down cause and effect somehow.

On the mental side of things, you are into 'failure mode analysis'; identifying what could cause the latch-up and what in turn could bring that cause about - the cause and effect could be vey far removed. Have a good long think about what could go wrong, what could cause that, and what in turn could cause that; it looks like you've already started.

Don't discount anything ! The most unlikely possiblility will, by Sod's Law, be the culprit, and the last thing to get looked at.

Is the 18A latching up due to 'fault' or is it simply waiting for some serial data which never arrives ? Is there some code branch which only rarely happens which could cause a problem; a simple code 'bug' or something more complex like exceeding the allowed depth of GOSUB nesting ?

My first thought would be to try a different power supply rather than the PC PSU and batteries. Could it be that it's the actual PC PSU itself cauing the problem ? Slapping some smoothing caps on the power rails would be something worth trying.

Also, what voltage are you running your PICAXE's at; is it within the spec for the particular Firmware versions used ? Is the supply simply collapsing to too low a voltage when something switches ?

Your first preliminary test though ... Replace your code with something which doesn't interact with anything else but just flashes a LED. If that keels over, then you will probably have a much simpler system to deal with during debugging. If it works, then you may be able to say that the PSU isn't a problem in itself, and either way, it will help you discover what does and doesn't work.

Good luck.
 

wardbob

Member
Check the diodes to make sure they are OK. A bad one could be letting back emf through. Not likely, since it appears to depend on low voltage on batteries, but a simple thing to check.
 

ArnieW

Senior Member
Thanks for the quick responses. I've already done some testing between the two picaxes - downloading code specifically to test them - but there is quite a bit more analysis to do.

The supply may not be loaded enough to regulate properly, so I'll look into that. I'll do a test on flat batteries; and another with simply well charged batteries and no PC supply.
And a test with simple code that just cycles an output on or off.

It is a good thing I've got some leave coming up soon because it sounds like it might take some sorting, so bear with me and I'll let you know of progress.

Just for some added info, yesterday I had it running in the background and it had not failed in over 5 hours. At another time yesterday it failed in 10 mins. The longer times are more common though. It has been running for hours today without fault.

thanks, Arnie
 

TEZARM

Senior Member
TRY PUTTING A 100NF CAP DIRECTLY ACROSS PICAXE (BASICALLY ON TOP OF IT), I MEAN VERY CLOSE. THIS DOES DEFINITELY SOUND LIKE A POWER SUPPLY PROBLEM. I HAVE HAD SO MANY POWER SUPPLY PROBLEMS BEFORE WITH THE PICAXES. THEY ARE VERY FUSSY LITTLE THINGS. BUT NOW HAVE THE PROBLEMS SORTED. PICAXES CAN DO SO MANY STRANGE THINGS IF THE POWER SUPPLY IS NOT RIGHT FOR THE APPLICATION YOU ARE USING IT FOR. YOU COULD ALSO TRY PUTTING SAY AROUND 10UF CAP NEXT TO THE 100NF ASWELL.
 

Rickharris

Senior Member
I agree with the PSu theorys. We have often had problems with 28's which seem to reset when driving motors through an L293 even though the current is within spec and voltages are spot on

Ofte fresh battries work for a while but then go the same way. Never had this problem with 08s or 08m
 

BeanieBots

Moderator
Check the obvious things first like pull ups on reset pins and pulldowns on serin.
As an aside (I don't think it is your problem), batteries are NOT very good at absorbing spikes so putting caps on the LM317 is a good idea.

You seem to have ruled out the software but I'm a little suspicious because you mention outputting 100Hz at 50% duty and also talk of serial comms. How are you doing that because the 18A will stop while it waits for a serin?
 

hippy

Technical Support
Staff member
Just a note on operating voltages with respect to the post from rickharris -

According to the datasheets I have, all PICAXE's should work down to 4.0V, an 18 down to 3.0V, and the 08/08M down to 2.2V ( 3.0V for an 08M at 8MHz ).

This probably explains why 08/M's are more immune than other PICAXE's.
 

ArnieW

Senior Member
Thanks again to all who've posted. It looks like this is more common an issue than I'd first thought.

I understand your suspicion BeanieBots about code. I dismissed this without explaining why I wasn't overly concerned about it.

There are a number of reasons.

The testing has been consistent: that is every 15 seconds the 18A receives a serin command line and evaluates it. This is the info it needs for determining output switching configuration. During testing, the configuration has not changed, so every 15 secs the 18A should be reading the same setup.

As the problem has been seemingly random, I'm less inclined to see it as a code issue. The coding itself is not complex either, there are no subroutines it may not be returning from etc. I will still do the very simple test suggested of only cycling a single output.

Another reason I've not been concerned about the serin part of the code is that when the 18A is operating successfully, I can literally see a serin being received. This is because when it happens the critical outputs (ie. heaters) are set low, and the non critical outputs (ie. pump) that were high remain high. During this phase of testing, there is sufficient delay built in to watch it turn off heating lines until the new serin information has been received and processed.

At the moment I'm using a variation of Hippy's serin interrupt coding. The variation is that it doesn't currently use an interrupt per se, but rather regularly looks at the serin line and then jumps when the line goes high. I will eventually do the more orthodox interrupt subroutine, but for now it simply works on gotos.
 

ArnieW

Senior Member
An update on progress.

24 hours ago I put a couple of electrolytic caps on the supply line to both the 40X and 18A. (I should mention I have had some trouble with the 40X freezing, but not as often as the 18A). These caps were ones that were handy rather than carefully selected values. At the 40X end is a 10uF, and at the 18A end is a 2.2uF. Both are electrolytics.

Since then I have not had any trouble at all. It is too early to draw conclustions, but this is the best/most stable result since I became aware of the problem.

I will continue with some more rigorous testing when I have the time, but that looks like being a month away.

cheers, Arnie
 

BeanieBots

Moderator
Now that you have mentioned that the 40X also locks, I would put money on it being a power supply or noise issue. Switching 3600W is bound to produce spikes however resistive the load is. I would concentrate my efforts at stopping them from getting in. Apply filtering to ANY lines comming in.
 

premelec

Senior Member
I see that you are trying to switch 3600 watts with a low level line but I didn't see what you are driving - Relay ? SS Relay? Triac? I would hope you have opto-isolation somewhere in the control and you also should have a snubber on the high current line - inductor and capacitor as well as local bypass and electrostatic shielding of PICAXE units. Radiated EMI pickup is a real possibiilty when microwatts affect the PICAXE and thousands of watts are being switched. You can use an AM radio to 'listen' for EMI around the unit - I'd suggest reducing the load to a few tens of watts [and check zero watts!] and see if the problem still occurs and then increase the load till it happens - Good luck with it...
 

ArnieW

Senior Member
BeanieBots & premelec,

thanks again for your help. A few things.

- the original lockup occurred without the elements connected, so no noise from them.

- after installing the caps I mentioned in an earlier post, I had a trouble free run with all power connected. (I will continue to isolate the reason to increase reliability and for peace of mind).

- the heaters are controlled via zero-crossing optos that drive triacs. In series across the switching terminals are a resistor (39 ohms) and capacitor (0.01 u) acting as a snubber.

- also on the boards I have a wide range of other devices that may be potentially more noisy than the heaters. These include servo motors, a stepper motor, a couple of relays, some water solenoids, a buzzer, some fans and a couple of 240VAC motors.

* what do you recommend to minimise noise, what is good practise? bypass caps? ferrite beads? metal box?

** The machine ran without fault over Sunday night and most of Monday - the result a nice Belgian Ale for our troubles. Thanks to all who have assisted so generously of their experience and taking the time to do it.

Arnie
 

bobrayner

Member
Arnie
If you really need to get rid of externally generated noise the nice way to go would be to put your sensitive circuit in a metal box (preferrably steel if possible) and bring external inputs via "feed thru" caps with maybe a ferrite bead on the wire. These caps are a sort of "coaxial" arrangement where the through connection is a straight wire with the capacitor formed around it. Not easy for the hobbyist to get. Not the sort of DSE or Jaycar component. Farnell have a range but if you cannot solder to the box and need the threaded type you are looking at fairly serious dollars.
A word of advice re filters in general. Care needs to be exercised when selecting values as incoming data info can be corrupted beyond use. DC lines not too critical. It is good practise to only use a capacitor AT ONE END OF A WIRE ONLY or you will end up with a tuned circuit. This will select any resonant component out of the noise and sometimes ends up with quite high circulating currents which will produce significant voltage drop across your filter cap right where you don't want it. This can be illustrated if you sketch a circuit with 2 caps and a wire between them. Now replace the wire with an inductor (which it is) and see what you have. The value of this inductance of course varies widely depending on length, diameter and routing but IT IS THERE. Indeed with half way decent instrumentation the inductance of a straight piece of wire a few centimeters long can be readily measured. Agreed the average hobbyist would be unable to do this but the inability to measure such things does not remove them and the affects should not be ignored.
Cheers BobR
 

BeanieBots

Moderator
Bob has covered most of it. The other area is layout. This is hard to explain in text but consider something like the switching of a relay. When the coil is turned off, there is a large back emf generated. To avoid frying the switching transistor, it is common practice to fit a catch diode. That gets rid of the massive voltage spike but replaces it with a large current spike into the supply rail. Think about the path that spike will take, bearing in mind that tracks have both resistance and inductance.
 

bobrayner

Member
Beanie
This diode used to often be called a "Flywheel" diode. The energy stored in the coil of a relay is dissipated in the loop formed by the coil and the diode. Not much gets to affect the supply rail. Same applies to the diode across a motor when rapidly switched with PWM or similar. In both cases the diode has to withstand at least the operating current of a relay and the stall current of a motor and be fast enough to "catch" the back emf. For small relays 1N4148 small signal diodes are often used. Some DIP packaged relays have the diode built in so beware polarity.
Cheers BobR
 

BeanieBots

Moderator
I absolutely agree, that is why if the "loop" formed by the diode and the coil goes all around your circuit you end up with a "pulse transmitter".
Equally, consider the motor caps. Seems common sense to put them across the motor (when you know why you are doing it) but putting them on the drive output gives exactly the same circuit diagram if lead resistance/inductance is not taken into account.
 

wardbob

Member
The point is that the loop should be made as small and local as possible by putting the diodes/caps as close as possible to the relays/motors. The current loop itself will radiate less if its area is kept as small as possible.
 
Top