servo motor question

pfroment

New Member
I designed a very simple circuit using 2 5v relays and 2 push button switches to drive a servo forward and reverse.
I set it up on a breadboard and use 2 leds to simulate the servo. It works perfectly. I plug in the servo where the leds were wired. test it out and nadda...unplug the servo and it works perfectly again. If i power the relay coils directly the servo works fine. Why is this happening? Any ideas?
Paul f
 

lbenson

Senior Member
Show your circuit. Servos typically take timed pulses to drive them, so how are you working them with relays? Do you have a servo or some other type of motor?
 

westaust55

Moderator
Yes, please provide your schematic/circuit diagram and if possible a link to your servo motors.

Your description seems more like conventional motors.

Servo motors have theee wires.
Two for the power supply which is polarized and you do not revere it.
The third wire is for a signal with a timed pulse (every 20 ms) that sets the position for the servo motor output shaft.

To my knowledge, There should be no need for two relays unless it is a "conventional" motor.
 

AllyCat

Senior Member
Hi,

Yes, I suspect that you have a "conventional" (dc brushed) motor in some form of servo-mechanism. BTW, I'm equally confused by the so-called "Continuous Rotation Servos", since they don't actually have any Servo (control/feedback) action.

But back to your basic problem: How much current is passing through the LEDs, compared with that required by the relay coils? And are the PICaxe pins pulling the load High (with other load terminal to ground) or pulling Low (with a load terminal to the supply rail)?

Cheers, Alan.
 

pfroment

New Member
I hacked the Servo so it is a conventional dc motor. I am not at home so I cannot currently supply the diagram. Will so once I get home
 

pfroment

New Member
here is my diagram:

main:
do
do : loop until pinb.1 = 0 ' loop until the pin goes high
pinb.1 = 1 'pin b.1 goes high via push button switch 1
low c.1 ' led red
high c.2 'led green
toggle b.3 ' turns on relay coil 1 via a Darlington transistor
pause 750
toggle b.3
gosub tr2a
loop
return
tr2a: do
do : loop until pinb.2 = 0' loop until the pin goes high
pinb.2 = 1 ' goes high via push button switch 2
low c.2 ' led green
high c.1 ' led green
toggle b.5 ' turns on relay coil 2 to reverse motor
pause 750
toggle b.5
gosub main
loop

the servo motor is a straight dc motor ( I hacked it). i am using 2 led's to simulate the forward and reverse motion of the motor.
I works perfectly. When i plug in the motor in place of the leds, i get nothing when I push the switch. The switches are wired as pull down so i am feeding 0v to the pin. if i jump 5v to pins b.3 and b.5, the motor works perfectly. I am at a loss. Could the power supply not be heavy enough to run everything?
 

lbenson

Senior Member
do : loop until pinb.1 = 0 ' loop until the pin goes high

Either your comment or the code is wrong.

do : loop until pinb.1 = 1 ' loop until the pin goes high

do : loop until pinb.1 = 0 ' loop until the pin goes low

Same for the line immediately following "tra2: do".

"return" needs to be at the end of tr2a, not where it is (but your gosub main also needs to be removed--when you're calling a subroutine which calls the calling routine, you will quickly run out of stack space for the return address).

If you post code between the tags, "[ code]" and "[ /code]" (without the spaces I've put in), your code will show any indentation which you have, which will make it easier for us to read.

I haven't looked further. If you walk it step by step through the simulator, you may better understand exactly what is happening.

Which picaxe? It's best to put the "#picaxe 14M2" (for example) at the top of your code.
 
Last edited:

AllyCat

Senior Member
Hi,

I can't see any (schematic) diagram so don't know how the relays are connected, or if you've included decoupling capacitors and flywheel diodes, etc. What is the resistance of the relay coils and resistor values in series with the LEDs?

But you certainly appear to have some issues with the program structure and comments: As said above, there shouldn't be a return after the end of the main: segment (which will never be reached ayway), you shouldn't call (gosub) main and the subroutine tra2: doesn't have the required return.

pinb.1 normally refers to an input so it is "unusual" for the program to assign it a value (=1). The PE/compiler doesn't flag it as an error, but it's probably not doing what you intend or expect.

As for the comments: toggle b.3 ' turns on .... is misleading, it might turn on or off depending on its present state. high c.1 , high c.2 and low c.2 are all marked as 'ledgreen.

Cheers, Alan.
 

pfroment

New Member
I got it working. What I did is power the relay contacts with a separate power supply. If I run the entire project with one supply, it won't work.
I am using a 300 watt computer power supply, so I know I have enough power to that project and then some. I an curious as to why I need two supplies, any thoughts?

PS I am still not sure how to post code on the forum.
 

AllyCat

Senior Member
Hi,

Have you put a decoupling capacitor directly between the PICaxe Supply pin and Ground? With a computer power supply like that you may need several, perhaps 100nF ceramic and 100 uF electroltyic in parallel. But for several reasons, the use of computer power supplies is generally NOT recommended.

Put #terminal 4800 and then sertxd(" Starting ") in two lines near the top of the program. After the program download, that should open up the Terminal Emulator window and write Starting in the window once. If it prints it more than once, then the PICaxe is being Reset, probably due to "noise" on its supply rail.

To insert program text into a post, copy it into the clipboard and paste it between [ code] and [ /code] tags (with no spaces). Or simply select the text within the Program Editor and click Edit : Copy for forum.

Cheers, Alan.
 

westaust55

Moderator
The need for separate power supplies for the PICAXE and motors is quite understandable.

Servo motors often draw around 1 amp (unless they are very small or very large) and may peak briefly at several amps for a couple of usec. The high current draw causes the voltage to dip and if the PICAXE is connected to the same supply it will likely reset when the voltage dips and recovers so the program keeps restarting.

Even just adding capacitors at the PICAXE would not be sufficient as they would discharge rapidly to help support the motor induced voltage dip. An isolation diode between the servo motor and PICAXE supplies would be required so the bulk energy reservoir capacitor (electro or tanatalum type) is only supporting the voltage to the electronics/PICAXE.

Electrical noise from the motors and PICAXE itself can also cause problems. Hence the mention of decoupling (filtering) capacitors previously by Alan.
 
Last edited:

pfroment

New Member
Thanks to everyone for your help. the decoupling capacitor did the trick. I sure have a lot more to learn. again thanks
 

rq3

Senior Member
Thanks to everyone for your help. the decoupling capacitor did the trick. I sure have a lot more to learn. again thanks
The subject of decoupling (by-pass) capacitors comes up all the time. These capacitors are such a piece of "tribal knowledge" within the experienced design community that they are often not shown on schematics. It is assumed that their presence is required.

It is almost impossible to have too much decoupling. A few exceptions are:
1) On the output of voltage regulators where incorrect capacitance, or capacitance of the wrong ESR (equivalent series resistance), make the regulator unstable. The regulator data sheet is the guidance for this.
2) On the output of voltage regulators, where shorting the INPUT to the regulator, even momentarily, causes the output capacitor to discharge back through the regulator, destroying it. The regulator data sheet is the guidance for this, too.

Decoupling caps serve two functions. Big, fat, electrolytics like aluminum and tantalum act as small batteries. They can provide very heavy currents (amperes) for a short period, and prevent the power supply to the chip from sagging in voltage when the chip is switched at high speeds and heavy currents. Many folks think that because their circuit is only drawing milliamps, little bypassing is needed. Not so! It's drawing milliamps on average, but digital circuits switch those milliamps in nanoseconds. The instantaneous current is very, very high. The electrolytic cap acts as a local battery to provide that current, which the circuit's wires and printed circuit traces are preventing from getting to where its needed fast enough.

Unless there is a good reason NOT to use them, solid tantalum are almost always a better choice than aluminum electrolytics. They don't rely on liquid electrolyte. They can't leak. They're smaller. Their capacity (generally) changes less over temperature. They (generally) have a lower ESR, so can supply more current faster.
The downside is that they (generally) cost more. Sometimes, a lot more.

The other, little, guys, like the 0.1 uF and 0.001 uF ceramic capacitors are for radio frequency by-passing. Their function is to block direct current, while allowing high frequency impulses from the rapid digital switching to shunt to ground, keeping the chip's DC supply clean and free of transients that might be interpreted as a logic signal.

None of this works unless the capacitors are mounted as close as possible to the source of the noise, AND couple to a good COMMON ground. How close? One inch is a good rule of thumb, closer is better. What's a common ground? Ideally, a plane of copper embedded within the printed circuit that floods the entire circuit area. That's usually what multi-layer boards are all about, and the higher the operating frequency, the more critical the grounding and de-coupling becomes.

Flying wires and multi-point grounds on a bread-board at high frequency are usually doomed to failure, especially when you throw a noisy, high current device (like a motor) into the works.

But with good layout, and good by-passing, there is no reason a Picaxe, a 5 amp stepper motor, and it's associated driver device can't get along happily on one small board, all driven from a common battery.
 

Buzby

Senior Member
Many years ago I built a little circuit with some CMOS chips and a 7805, but no decoupling anywhere.

The circuit didn't work.

A quick test with a multimeter showed the 5v rail was a perfect 4.95v, so I was all over the circuit looking for shorts, or breaks, or wrong wiring, all to no avail.

So time to bring out the big guns, and I put my scope to work.

The 5v rail which looked a solid 4.95v on the multimeter actually was a mess of high frequency noise, with dips down below 1v.

Sprinkling some magic caps around cured the problem, and my circuit worked.

Now I don't even do a quick lash-up test of any digital chip without a magic cap nearby.

Cheers,

Buzby
 
Top