Help for Picaxe 14m

marcis

New Member
Hi,
hello everyone, I am new to this forum.
Can you help me find out where the problem is on my stupid little program with a picaxe 14m? (to control two motors with relays)
This is the list:

; Troncatrice
; Programma per PICAXE-14

symbol motore_troncatrice = 2 ;output 2 >>> pin 11
symbol attuatore_scende = 5 ;output 5 >>> pin 8
symbol attuatore_sale = 4 ;output 4 >>> pin 9
symbol tt = b0
symbol zz = b1

symbol avvio = pin4 ;input 4 >>> pin 3
symbol finecorsa_sale = pin3 ;input 3 >>> pin 4
symbol finecorsa_scende = pin2 ;input 2 >>> pin 5

main:
if finecorsa_sale = 0 then
goto resetta
endif
low motore_troncatrice
low attuatore_scende
low attuatore_sale
tt = 0
zz = 0
if avvio = 1 then
pause 100
goto scende
endif
goto main

scende:
high motore_troncatrice
if tt = 0 then
goto ritardo
endif
high attuatore_scende
if finecorsa_scende = 1 then
low attuatore_scende
goto attesa
endif
goto scende

ritardo:
pause 3000
tt = 1
goto scende

ritardo1:
pause 3000
zz = 1
low motore_troncatrice
goto sale

attesa:
pause 5000 ;pausa di 5 secondi
goto sale

sale:
high attuatore_sale
if zz = 0 then ritardo1
if finecorsa_sale = 1 then
low attuatore_sale
goto main
endif
goto sale

resetta:
high attuatore_sale
if finecorsa_sale = 1 then
goto main
endif
goto resetta

In the simulation software is all very well, the programming of the chip is ok, but when I put the chip on the card hardware go haywire
Picaxe outputs on the card, are isolated by optocouplers to control the relay

Thank to all

(excuse my bad english)
 

kevrus

New Member
Welcome to the forum,

Just a quick guess, but if it works ok in the sim, are you missing some pull up/down resistors on the inputs hence they are floating?
 

marcis

New Member
Thanks for fast reply.

I use 3 inputs for the commands, one for start and 2 in the end 2 stroke engine, all inputs have a 10k pulldown resistor.
 

marcis

New Member
Here's more information to understand the problem.
If the outputs of the chip I connect the leds, does everything a regular basis, when I link the relays then goes haywire
 

hippy

Ex-Staff (retired)
That sounds like an electrical noise issue, back-EMF, a circuit wiring problem, or maybe the relays switching are collapsing the power supply. Can you post a circuit diagram ?

Also try a simpler test program; something which just switches one relay on and off.
 

BeanieBots

Moderator
Need a circuit diagram before anyone can comment on hardware issues.
Anything else will just be guesswork and lots of frustration.
Common issues.
No clamp diode on relay coils.
Insufficient decoupling for PICAXE.
Power supply collapse.
Circuit construction error.
Overload on PICAXE OP. (eg relay connected to OP).

No point in making more guesses until we see a circuit.
 

marcis

New Member
Right.
This is a section of 3rd
are all equal according to this scheme.
The supply seems to be just, without picaxe on the card can activate the 3 relays simultaneously without voltage drop

scheme.JPG
 

BeanieBots

Moderator
That part of the circuit is fine.
(except it's draw back to front. Signals should go from left to right).

Does your PICAXE have a 100nF cap close to it's power pins?
What does your 5v circuit for the PICAXE look like?
Do you have the correct pull-down on serin. (eg download circuit)?
Does the 12v ground share current with the PICAXE 0v?
 

sghioto

Senior Member
marcis,

Should have a 10K resistor between the base of the BCX38 and the opto-isolator. The "on" resistance of the opto is fairly low, you don't need or want the excessive base current. Not that this will fix the problem your having but it's the correct way to connect the transistor.

Steve G.
 

marcis

New Member
well,
this is the correct scheme i have, the first post was on memory:

Immagine1.JPG

this is my power supply:

Immagine.JPG

excuse my bad english again
 

fernando_g

Senior Member
Like Hippy says;
try a simple program to turn on and off the relays by themselves, the motors, etc.
That way you'll isolate what is causing the problem.

This approach is called "divide and conquer"....you divide a circuit into small sections and test each section individually.

Also, if you have access to an oscilloscope, it would be worthwhile to monitor the power supplies while you do that.
 

marcis

New Member
How Hyppy and Fernando advise,
I did this little test 5 minutes ago,
this routine works with all the relays

symbol motore_troncatrice = 2
symbol attuatore_scende = 5
symbol attuatore_sale = 4

symbol avvio = pin4

main:
low motore_troncatrice,attuatore_scende,attuatore_sale

if avvio = 1 then
pause 100
goto relays1
endif
goto main

relays1:
high motore_troncatrice
pause 5000
low motore_troncatrice
goto relays2

relays2:
high attuatore_scende
pause 5000
low attuatore_scende
goto relays3

relays3:
high attuatore_sale
pause 5000
low attuatore_sale
goto main

but if I add other breaks do not work anymore

symbol motore_troncatrice = 2
symbol attuatore_scende = 5
symbol attuatore_sale = 4

symbol avvio = pin4

main:
low motore_troncatrice,attuatore_scende,attuatore_sale

if avvio = 1 then
pause 100
goto relays1
endif
goto main

relays1:
high motore_troncatrice
pause 5000
low motore_troncatrice
pause 1000
goto relays2

relays2:
high attuatore_scende
pause 5000
low attuatore_scende
pause 1000
goto relays3

relays3:
high attuatore_sale
pause 5000
low attuatore_sale
goto main

Is the problem inside the Picaxe ? :confused::confused::confused:
 

hippy

Ex-Staff (retired)
Is the problem inside the Picaxe ?
I would not have thought so. As best I can see is that you have added two PAUSE 1000.

Does it work if you replace your relays with suitable LED+Resistors ? If so then the issue is definitely related to your hardware.
 

marcis

New Member
Perhaps with the leds work, but in the last test because the hardware is working good and if I add the 2 "pause 1000" no longer works?

therefore it is not the hardware, though with 2 "pause" in more stops working

i hope my english is clear
 

hippy

Ex-Staff (retired)
There is no denying that the combination of adding the pauses and using physical relays exhibits the failure but nothing which absolutely demonstrates which it is that causes the failure.

In terms of analysing which could be responsible it is necessary to determine the possible failure modes caused by the addition of each. I would venture that there are few failure modes which would be introduced by the addition of pauses, in contrast there are many which could be introduced by the addition of relays.

The most likely failure mode introduced by adding a pause is that it allows time for the PICAXE to be affected by an adverse event or failure from elsewhere. Probably the most likely reasoning for that happening would be floating and improperly pulled-down or pulled-up inputs including Serial In and Reset on PICAXE's which have that, or the pause allowing a state which is a failure mode ( supply sag, over-voltage, EMI build-up ) to have time to impact on the PICAXE. In all these cases though it is not the PICAXE itself which is the root cause of failure.

It would, however be worthwhile posting your circuit diagram of the PICAXE controller. Also, with respect to your power supply circuit; the "common" connections for the three regulators are not shown. It is essential these are connected.
 

marcis

New Member
I do not want to be quite controversial and not take my response as an insult.

But your response seems a little philosophical, and as far as I know, in electronics there is little philosophical.

As you can see above, mine is a stupid program. The mass of regulators is common to the whole circuit.

But...

if the same hardware works fine and if I add a "pause" of 1 second does not work anymore, it may be that the fault is the hardware?

This is the question...

Tomorrow I post the complete scheme of my circuit, the original programm i would to use is on the my first post

thank you to all :)
 

hippy

Ex-Staff (retired)
One has to be philosophical even in electronics; when a chain snaps is it because the weight was too much or the chain too weak, is it that adding the pauses causes a failure or not having them prevents it ?

In a perfect world the relays would switch and the PICAXE would work with or without pauses. The challenge is in determining why we do not have such a perfect world.

In my experience there is nothing in adding a pause that should cause a problem with the operation of the PICAXE and thus it seems logical to me that the problem arises externally to the PICAXE. On the other hand it is well known that adding relays and motors can cause problems. Inherent problems may be masked depending upon circumstances yet show themselves in others.

The problem is that we are both speculating and applying logic to try and determine why the problem occurs without knowing the actual cause. There's not much else which can be done without more information.
 

BeanieBots

Moderator
I agree with Hippy's comments on this issue.
It may well be that the pauses simply allow time for the issue to manifest or more precisely, the lack of pauses 'masks' the underlying issue.

Either way, a full diagram will help to pinpoint what may at the root.
It would also help if you could post a picture of your layout.

A simple process of testing with/without each element WILL get to the bottom of this problem.
 

sghioto

Senior Member
Well for me I would not be surprised if the problem is the 14M. I've had issues with the 14M on a couple of occasions. One was that the "pulsout" command would not work on all outputs. The only way to get certain outputs to pulse was to use the "high", pause and low" commands. I remember Technical saying something like limitations or firmware trade offs in the 14M.
My point is can you try your program and hardware using a 18X or 20M?

Steve G.
 

hippy

Ex-Staff (retired)
If that is the complete circuit it likely explains the behaviour and why pause shows up the problem while not having pauses masks it.

It is not clear from the diagram what the switches on the right connect to at their top but it would be logical to assume one of the power rails, most likely 5V.

When any one of those activates it creates a dead short to 0V which will collapse the power supply. The 7805 regulator will go into over-current mode or over-temperature mode and shut down. As a consequence of a collapsing power supply the PICAXE will not be able to function correctly and will not be able to hold the relays energised. All manner of other unpredictable behaviour may occur during the failure and when the fault condition removes itself.

This should theoretically happen whether the PICAXE has pauses or not but given electronic systems are not ideal by nature ( wires and contacts have resistance, over-current and over-temperature detection are not instant, and components have internal capacitance ) I can only presume that, without the pauses, the collapse does not occur quickly enough to cause catastrophic failure before being cleared and the PICAXE can recover and continue ( or seems to ).
 

hippy

Ex-Staff (retired)
As a rule of thumb I go with 10mA for the PICAXE ( it's usually less ), and with three optos via 330R, 15mA each, you are looking around 60mA for the PICAXE part of the circuit.
 

hippy

Ex-Staff (retired)
You need to put resistors ( 1K to 10K ) in each path from the switch to 0V. That should hopefully solve the problems you are having.

Code:
                     -.-
                      |
                   _| O
                  |_|
                    | O
             ___      |
Input <-----|___|-----{
             1K      .|.
                     | | 10K
                     |_|
                     _|_ 0V
 

fernando_g

Senior Member
This is not the first time I have seen a perfectly OK circuit which is being corrupted by ground noise. I wish I had a dollar for each time a ground loop has caused a circuit, digital or analog, to misbehave.

Although you did the right thing to use optocouplers on the outputs, all of your grounds are still tied together. Depending on the layout, this could cause enough ground bounce noise to cause the PICAXE to go haywire.

You could do a simple modification, as shown in the attached proposed circuit. Esentially use a 9v battery to power (via the 5v regulator) all the logic circuitry. All the logic grounds should be isolated from the power grounds (the grounds which I've circled) that also includes the motor ground.
 

Attachments

MartinM57

Moderator
DELETED: but just to confirm, you have implemented the circuitry in post #26 for the switches and it still does not work?
 

marcis

New Member
Thanks for posting Fernando, your advice is very interesting and I'll try this too, but I find it inconsistent with a previous answer given by Hippy who claimed to check if all the ground were connected togheter.

I'm still doing tests when I have some free time
 

marcis

New Member
I would like to resolve this problem, otherwise I have to study a circuit with traditional electronics. This system seemed the easiest solution, but ....
 

BeanieBots

Moderator
Just to conform, as Hippy points out, the switches short power to 0v in the original circuit. Have you now used the correct wiring as per post #26?

Double check the diodes on the relay coils are the correct way around.
Does the problem still happen with the motors disconected?
 

Dippy

Moderator
Edit: Crossed with BB. So, please deal with his questions first.

I think we need to clarify the circuit as it stands now...

1) The switch inputs in your original schematic are totally unsuitable. As pointed out by hippy they will simply short the supply. As BB asks; have you corrected them?

2) Grounds. As pointed out these could be giving problems. If you have commoned grounds these should be thick tracks so that there aren't significant v-drops when on-load or transients during swithcing. As suggested previously, use careful ground routing to prevent nasties in the ground routes.

3) You SHOULD have healthy decoupling capacitors on your PICAXE + & 0V (Gnd) pins - typically >47uF electro p//d with 100nF ceramic.


This simple circuit should be quite easy, and , unless there is a faulty component, is most likely an error in wiring or unsuitable wiring or track layout.
Is all this on a nice PCB or hairy breadboard?
 

marcis

New Member
Now use the wiring of post # 26.
The last test was with the motors disconnected, and only with relays, use only the switch "start" without the other 2 switches to "end run".
Today I tried this:

symbol motore_troncatrice = 2
symbol attuatore_scende = 5
symbol attuatore_sale = 4

symbol avvio = pin4

main:
let pins = 0
if avvio = 1 then relays1
goto main

relays1:
high motore_troncatrice
pause 5000
low motore_troncatrice
goto relays2

relays2:
high attuatore_scende
pause 5000
low attuatore_scende
goto relays3

relays3:
high attuatore_sale
pause 5000
low attuatore_sale
goto main

and it work, and then

symbol motore_troncatrice = 2
symbol attuatore_scende = 5
symbol attuatore_sale = 4

symbol avvio = pin4

main:
let pins = 0
if avvio = 1 then relays1
goto main

relays1:
high motore_troncatrice
pause 5000
low motore_troncatrice
goto relays2

relays2:
high attuatore_scende
pause 5000
low attuatore_scende
pause1000 <<<<<< Here tilt
goto relays3

relays3:
high attuatore_sale
pause 5000
low attuatore_sale
goto main


i am going crazy
 

hippy

Ex-Staff (retired)
What do your relay contacts connect to and how arethey wired; a circuit for that would be useful.

As best I can tell from your PCB, activating the relay on pin5 (top) and pin4 (middle) together will create a short between 24V and 0V.

If it works with LED's but not with relay coils, that suggests it is something to do with the relay circuits. You could try it with one relay at a time, the others replaced by LED's, then with two relays and see which combinations cause a problem. You can also try changing the order of activation and seeing if you get the same problems.
 

kevrus

New Member
I think Hippy has a point about the relay contacts, can you physically remove the relays from the pcb and just run some flying leads to the relay coils, thus totally isolating the contacts from the pcb?
 
Top