# Using a 556 to control RC servo speed

#### MikeK

Joined Apr 1, 2016
34

I'm using a 556 to slow down a Tower Pro SG 90 servo for a model railroad crossing gate. I'm using 'Frequency' to control speed, 'High-Time' to control position. Anyway, the action is a little jerky at the speed I like. I would like to smooth this out. Any ideas?

#### jpanhalt

Joined Jan 18, 2008
8,508
Using frequency to control servo speed is an old way to do that and will result in jerkiness. In my experience, the range of available speeds is very limited. Above about 100 to 120 Hz, movement is extremely jerky. I suspect the same at very low refresh rates. I did those experiments about 10 years ago and don't recall the details. My advice is to use a microcontroller and slowly ramp up or down the pulse width to control speed.

John

#### GopherT

Joined Nov 23, 2012
8,012
View attachment 103528 I'm using a 556 to slow down a Tower Pro SG 90 servo for a model railroad crossing gate. I'm using 'Frequency' to control speed, 'High-Time' to control position. Anyway, the action is a little jerky at the speed I like. I would like to smooth this out. Any ideas?
I thought most servos want 50Hz and you control the "high" time to control position of the servo.

#### bertz

Joined Nov 11, 2013
327
View attachment 103528 I'm using a 556 to slow down a Tower Pro SG 90 servo for a model railroad crossing gate. I'm using 'Frequency' to control speed, 'High-Time' to control position. Anyway, the action is a little jerky at the speed I like. I would like to smooth this out. Any ideas?
Couple of things:
It is poor practice to power the servo from the same supply as the controller. Best to use a separate supply. Insert a 330 ohm resistor in series with the white (signal lead) going to the servo. Also, put a 0.1 uF cap across the red and black wires. Most low priced servos use brushed motors and they are noisy as hell.
If that doesn't solve your problem, do as JPH suggests and use a microcontroller. I would use a PICAXE since they are cheap, easy to program and have lots of uses in a model RR. I could post the code for you if that is the direction you think you might want to go.

#### Alec_t

Joined Sep 17, 2013
10,746
Here's a simple alternative solution.

R4/R5/U1a/U1b form a wide-hysteresis Schmitt trigger which, with R6/C3 makes a fixed frequency ~ 50Hz oscillator. The pseudo-triangle wave output taken from C3 is summed by R8/R9 with a control voltage from cap C4. The sum is the input to gate U1c, which generates a square wave with a pulse-width dependent on the control voltage. Flipping the switch will cause the pulse width to go from <1mS to >2mS or vice versa over an interval set by R7/C4. With the component values shown this is about 5 secs.

Joined Jul 18, 2013
19,765
@MikeK For future, can you place RC in the title then is avoids unnecessary reading/deciphering of the posts when using the broad universal term 'Servo'.
Max.

#### bertz

Joined Nov 11, 2013
327
Here is an alternative using a microprocessor, in this case a PICAXE 08M2. In this scheme an approaching train triggers a signal to the microprocessor to initiate the closing of the gate. For purposes of this example, the signal to close the gate will be a logic HIGH on pin C.1.

When pin C.1 goes HIGH it initiates the closing sequence. The speed of closing is governed by the pause command. A longer pause will result in a slower gate motion. When the train passes, pin C.1 goes LOW which initiates the raising sequence. Here is the code:

Code:
'******************RR Crossing Gate.bas****************
'Version 1.0
'AJZ/April 1, 2016
'this code is used to drive a servo operated crossing gate
'based on a digital input signal

'====Input=======
symbol trigger = pinC.1        'signal to raise & lower the gate

'===Outputs===
symbol gate_Servo  = C.2    'PWM out to servo

'===Variables===
symbol pos0 = b0

'===Directives===
#com 3                'specify serial port
#picaxe 08M2            'specify processor
servo gate_Servo, 150        'make sure gate is in raised position
pause 500

main:
do
if trigger = 1 then        'train detected
exit
end if
loop while trigger = 0
gosub activate

activate:
for pos0 = 150 to 80 step -1         'lower the gate
servopos gate_Servo, pos0
pause 5                'sets the lower speed
next pos0
do
if trigger = 0 then            'train clears the sensor
exit
end if
loop while trigger = 1
pause 500                    'pause to let the last car clear
for pos0 = 80 to 150             'raise the gate
servopos gate_Servo,pos0
pause 5                'sets the gate speed
next pos0
goto main
And here is the circuit:

#### MikeK

Joined Apr 1, 2016
34
Couple of things:
It is poor practice to power the servo from the same supply as the controller. Best to use a separate supply. Insert a 330 ohm resistor in series with the white (signal lead) going to the servo. Also, put a 0.1 uF cap across the red and black wires. Most low priced servos use brushed motors and they are noisy as hell.
If that doesn't solve your problem, do as JPH suggests and use a microcontroller. I would use a PICAXE since they are cheap, easy to program and have lots of uses in a model RR. I could post the code for you if that is the direction you think you might want to go.
Thanks Bertz (and all other replies). I'll try your recommendations before going the PICAXE route. I'm trying to keep this simple.
PS, how would I power the servo from a different supply on a model train setup? The track power box has an AC accessories output of about 18 volts, which really heats up my bridge/7812. I've gone to using a larger voltage regulator with it's own bridge.

#### bertz

Joined Nov 11, 2013
327
PS, how would I power the servo from a different supply on a model train setup?
Use one of these.

#### MikeK

Joined Apr 1, 2016
34
Thanks, I'll do some tests. Maybe I'll use another one to power the rest of the crossing controller, instead of the whole track transformer-accessory outlet-power supply route. Less mess, and it leaves the accessory outlet for some other use.

#### MikeK

Joined Apr 1, 2016
34
I've built a circuit board using IC chips (74ls123 voltage comparator for photosensors, a 556 to control the servos, a 555 to control the flashers, and a dpdt relay between the sensor chip and the servo chip to determine up or down on the gates). The circuit operates fine away from the track, but every time I connect or even get near the track and run a loco, the circuit picks up noise and acts up. Just turning on the track controller is picked up, triggers a reaction from the 74ls123. I have put .1uf disc caps on the track bus and only feed battery power to the crossing controller. I tried snubbers, and a home-made Butterworth filter. Still the controller picks up the noise. My test track is a circle. DC.
Any clues?

#### bertz

Joined Nov 11, 2013
327
I've built a circuit board using IC chips (74ls123 voltage comparator for photosensors, a 556 to control the servos, a 555 to control the flashers, and a dpdt relay between the sensor chip and the servo chip to determine up or down on the gates). The circuit operates fine away from the track, but every time I connect or even get near the track and run a loco, the circuit picks up noise and acts up. Just turning on the track controller is picked up, triggers a reaction from the 74ls123. I have put .1uf disc caps on the track bus and only feed battery power to the crossing controller. I tried snubbers, and a home-made Butterworth filter. Still the controller picks up the noise. My test track is a circle. DC.
Any clues?
Perhaps the 74LS123 is the wrong chip to use in this application. Consider the following taken directly from the TI application notes:

Special Considerations

Because these monostable multivibrators are half analog and half digital, they inherently are more sensitive to noise on the analog portion (timing leads) than standard digital circuits. They should not be located near noise-producing sources or transient-carrying conductors and liberal power-supply bypassing is recommended for greater reliability and repeatibility.

Also, a monostable should not be used as a fix for asynchronous systems; synchronous design techniques always provide better performance. For time delays over 1.5 s or timing capacitors over 100 mF, it is usually better to use a free-running astable multivibrator and a couple of inexpensive decade counters (such as a 7490A) to generate the equivalent of a long-delay one-shot. Astable oscillators made with monostable building blocks have stabilities approaching five parts in 100 and should not be used if system timing is critical. Crystal oscillators provide better stability.In all one-shot applications, follow these guidelines:

• Use good high-frequency 0.1-mF (ceramic disk) capacitors, located 1 to 2 inches from the monostable package, to bypass VCC to ground.

• Keep timing components (Rt, Ct) close to the package and away from high transient voltage or current-carrying conductors.

• Keep the Q-output trace away from the CLR lead; the negative-going edge when the one-shot times out may cause the C lead to be pulled down, which may restart the cycle. If this happens, constantly high (Q = H, Q = L) outputs with 50-ns low spikes will occur at the repetition rate determined by Rt and Ct. If sufficient trace isolation cannot be obtained, a 50-pF capacitor bypassing the C lead to ground usually eliminates the problem.

• Beware of using the diode or transistor protective arrangement when retriggerable operation is required; the second output pulse may be shorter due to excess charge left on the capacitor. This may result in early time out and apparent failure of retriggerable operation. Use a good capacitor, one that is able to withstand 1 V in reverse and meet the leakage current requirements of the particular one-shot.

• Remember that the timing equation associated with each device has a prediction accuracy. Generally, for applications requiring better than ±10% accuracy, trimming to pulse duration is necessary.

#### MikeK

Joined Apr 1, 2016
34
Thanks, I'll check my board against your recommendations. I have these little .1uf caps, the size of a small aspirin, will they do, or do I need the ones the size of a penny? (to bypass VCC to ground) I also have ones that are rectangular, purse-shaped.
The timing equation is probably ok, since I'm using a relay after the 74ls123, and using it's quick pulse to power a latching coil in the relay.
When the 123 is acting up, it rapidly fluctuates between the Q outputs. I have LEDs on the other relay pins to show me that the sensors are activated, and they flash rapidly alternately. The relay doesn't like that, I've already failed one. I expect the coils see parallel current, and one can't take it, just guessing.

#### GopherT

Joined Nov 23, 2012
8,012
Thanks, I'll check my board against your recommendations. I have these little .1uf caps, the size of a small aspirin, will they do, or do I need the ones the size of a penny? (to bypass VCC to ground) I also have ones that are rectangular, purse-shaped.
The timing equation is probably ok, since I'm using a relay after the 74ls123, and using it's quick pulse to power a latching coil in the relay.
When the 123 is acting up, it rapidly fluctuates between the Q outputs. I have LEDs on the other relay pins to show me that the sensors are activated, and they flash rapidly alternately. The relay doesn't like that, I've already failed one. I expect the coils see parallel current, and one can't take it, just guessing.
The size/shape/color of the cap is not important. The important part of the rating for voltage. There are other cap ratings but they seem to matter less when used as a simple timing capacitor for an application where this level of accuracy is needed. I have not see ceramic caps rated at less than 50V so you are likely ok with what you have. The big ones can be rated for 1000 V or more.

#### bertz

Joined Nov 11, 2013
327
Thanks, I'll check my board against your recommendations. I have these little .1uf caps, the size of a small aspirin, will they do, or do I need the ones the size of a penny? (to bypass VCC to ground) I also have ones that are rectangular, purse-shaped.
The timing equation is probably ok, since I'm using a relay after the 74ls123, and using it's quick pulse to power a latching coil in the relay.
When the 123 is acting up, it rapidly fluctuates between the Q outputs. I have LEDs on the other relay pins to show me that the sensors are activated, and they flash rapidly alternately. The relay doesn't like that, I've already failed one. I expect the coils see parallel current, and one can't take it, just guessing.
This thread is no good without pictures! Please post your circuit diagram - that way we can see what's going on. By the way, do you have a diode across the relay coil?

#### MikeK

Joined Apr 1, 2016
34
I'll try to put together a diagram, I make drawings of both sides of the board, from datasheets and breadboard work. It may be hard to see what's going on from them. Meanwhile, no, I don't have that diode across the relay, that's next. Would this diode keep the circuit from picking up signals from the train track. Keep in mind, my problem is this circuit is reacting to a nearby circuit, no actual wire connections...some kind of radio control??

#### bertz

Joined Nov 11, 2013
327
I don't have that diode across the relay, that's next. Would this diode keep the circuit from picking up signals from the train track.
No, this diode wont keep the circuit from picking up signals from the track. But it will protect whatever component is driving the relay (transistor?)
The best place for the diode is right at the relay, Cathode at the + end, and anode at GND.
my problem is this circuit is reacting to a nearby circuit, no actual wire connections...some kind of radio control??
No Mike it's not radio control. The source of the interference is most likely arcing at the brushes of the motor and possibly arcing between the wheels and the rails, especially if the track is dirty. So how do you deal with it? First make sure that your circuit has by-pass capaciors correctly installed at all the right locations. Rather than going into a treatise here on by-pass capacitors, I refer you to this article:

Then I would take a look at the motor. A good practice is that of soldering three ceramic capacitors (having a value between 10 nF and 100 nF) directly on the motor’s contacts, for the purpose of suppressing the noise coming from brushes rubbing on the collector. The capacitors have to be soldered between the two terminals and the frame, and possibly also one of the two power supply terminals. See attached photos.
These capacitors will do nicely.

Finally, I would take a look at your circuit. You have components that are highly susceptible to electrical noise (74LS123). It seems to me that you have far too many components to do a simple task. Raise & lower the crossing gate while flashing a couple of LED's.

#### MikeK

Joined Apr 1, 2016
34
Thanks so much for the help. I'll follow the advice of the link on caps. Meanwhile, yes, I have what seems to be a lot of components. The 74ls123 takes two photosensor inputs and has two low outputs and two high outputs. I use the low outputs for indicator LEDs to let me know if the sensors are working, and the high outputs to drive 337 transistors to operate the latching relay that then goes through a 556 to control the servos. The 556 does a nice job of slowing the servos down for a more realistic gate speed. I have not been able to smooth that out, the beginning of this thread.
I use a pin on the relay to operate the 555 alternating flasher and a recorder for loco horn sounds. Lots of stuff at a train crossing.
Since this has gotten overly complicated, I'm considering learning about the PICAXE chip. Programmable chips seem the way to go these days. Looks like more time down the rabbit hole for me.
I have lots of locos, and want this circuit to work for others without having to modify locos. Modeling these days either uses DC or DCC. Even the DC is not especially controlled by a big rheostat, but I think they chop it (PWM?) to allow the locos to crawl while still pulling a long train. All this fancy electronics makes for more noise, I'm sure.
I still contend that something funny is happening, my circuit fires a sensor LED when I turn on the track control, loco on the tracks or not. My track is a big (antenna?) circle and the crossing control circuit is right there next to the tracks. When a loco passes, a led fires. I'm temped to move it back to my work bench and have my wife operate the track to see how far the interference can travel. On my bench, or with the track power off, it works fine.

#### MikeK

Joined Apr 1, 2016
34
Bertz, the more I beat my head against the wall, the better the picaxe looks. What do I need to get started, where to get it? And will my photoresistors or phototransistors do for the 'digital input' ? I sure hope the picaxe is noise resistant. I think I read where the alternating flashers and recorder can be included, too.

#### bertz

Joined Nov 11, 2013
327
Thanks so much for the help. I'll follow the advice of the link on caps. Meanwhile, yes, I have what seems to be a lot of components. The 74ls123 takes two photosensor inputs and has two low outputs and two high outputs. I use the low outputs for indicator LEDs to let me know if the sensors are working, and the high outputs to drive 337 transistors to operate the latching relay that then goes through a 556 to control the servos. The 556 does a nice job of slowing the servos down for a more realistic gate speed. I have not been able to smooth that out, the beginning of this thread.
I use a pin on the relay to operate the 555 alternating flasher and a recorder for loco horn sounds. Lots of stuff at a train crossing.
Since this has gotten overly complicated, I'm considering learning about the PICAXE chip. Programmable chips seem the way to go these days. Looks like more time down the rabbit hole for me.
I have lots of locos, and want this circuit to work for others without having to modify locos. Modeling these days either uses DC or DCC. Even the DC is not especially controlled by a big rheostat, but I think they chop it (PWM?) to allow the locos to crawl while still pulling a long train. All this fancy electronics makes for more noise, I'm sure.
I still contend that something funny is happening, my circuit fires a sensor LED when I turn on the track control, loco on the tracks or not. My track is a big (antenna?) circle and the crossing control circuit is right there next to the tracks. When a loco passes, a led fires. I'm temped to move it back to my work bench and have my wife operate the track to see how far the interference can travel. On my bench, or with the track power off, it works fine.
I assume you are using pulsed DC control for your locos instead of DCC. Remember that pulsed DC can act very similar to AC except the waveform never goes below 0 volts. I like your idea of moving the control board away from the tracks (you indicate that it is right next to the tracks). Anytime you have a current carrying conductor it is surrounded by a magnetic field. If this field is collapsing on a regular basis (as in pulsed DC) it will induce a current in an adjacent conductor. Could this be the source of your problems? Move the control board some distance from the track and find out.

I sure wish you could post a schematic of your control board, it would make it easier to help you.