The circuit
The design goal for this circuit is to control a servo motor with a simple switch that selects one of two preset positions. In addition, the presets must be easily adjustable and provide precise alignment. First a recap of servo theory:
A servo motor sets its position by comparing the voltage off a potentiometer connected to the shaft to an input control voltage. In the case of the little RC servos we use, the control is provided as a series of pulses, and the servo translates the pulse duration into a voltage internally. This is essentially the same PWM system we use to control our trains. Different servos behave differently, but there is a loosely held standard that the midpoint of rotation will be specified by a pulse duration of 1.5 ms. The pulses are sent at 20 ms intervals or faster. The servo I am experimenting with (Parallax) has a 180° range of rotation specified by pulse durations from 0.75 ms to 2.25 ms. So the problem is to send pulses within that range at 50 hz or so.
The goto chip for analog timing is the venerable 555. We've seen this before:
Technical discussion you can skim over:
Even though this is a simple chip by modern standards, there's a lot of stuff in there. It all exists to manage the switching to charge and discharge a capacitor. Capacitor charging cycles are a popular way to mark time. Briefly, when the trigger input is pulled below 1/3 of +V, a memory cell (flip-flop) is set on. When the threshold pin is brought above 2/3 V, the flip-flop goes off. The output of the flip-flop is connected to a transistor in such a way that the pin labeled discharge is connected to ground when the flip-flop is off and unconnected when the flip-flop is on.
This circuit can be used in two ways:
Monostable or one-shot Astable, or oscillator
In both of these circuits, there is a capacitor connected to the threshold and discharge. On the left, the capacitor is connected directly to the discharge- when discharge is unconnected a resistor (RA) connected to +V can charge the capacitor. When the discharge pin connects to ground, the capacitor is discharged almost instantly. What makes the change happen? The trigger disconnects discharge, then the threshold pin reconnects it. This cycle will happen once, every time the trigger input is brought low. This is called monostable or one-shot operation. The time it takes for a complete cycle is 1.1xRAxC.
The right hand circuit is a bit more complex, with a resistor (RB) between the capacitor and discharge as well as between the discharge and +V. This means the discharge is gradual as well as the charge. The other change is a connection between the threshold and the trigger. That means when the capacitor has discharged enough to make the filp-flop flip, the circuit triggers itself for another go-round. Thus the circuit oscillates in what is called astable operation. The frequency is 1.44/((RA+2RB)C).
End tech talk, back to paying attention
Our servo circuit requires one of the above to produce a steady stream of pulses and one of the other to provide pulses of a controllable width. Here is a circuit that combines the two:
*Edit: 4/7/16 corrected C2 value
Note that the output of the oscillator section (left side) is perfectly suited to trigger the one-shot side. The resistor and capacitor values shown give a pulse frequency of about 70Hz and a pulse duration just shy of 2ms. How do we translate that into servo control?
There's another input on the 555 that seldom gets much discussion. This is the control voltage input-- most sources just tell you to put a small cap on it and don't say much more. But it's actually a very useful pin. If you look back at the drawing of the innards of the 555, you will see a set of three resistors-- these comprise a voltage divider that determines the 2/3 V and 1/3 V flipping points. The control pin lets us apply our own voltage to determine the point at which the circuit switches into discharge. (The trigger point will likewise change to 1/2 of that.) That of course will change the timing of the circuit. The section of circuit labeled preset is a voltage divider that will adjust the discharge point between 31% and 69% of +V. (The pots are 10k-- my cheap circuit simulator refuses to show the values.) This will set the pulse duration from 0.75 ms to 2.25 ms, just what the specs call for. Note that there are two preset voltage dividers, chosen by a switch. When the switch is thrown, capacitor C3 will smooth the transition from one voltage to the other, slowing the movement of the servo arm. Experiment with different values of C3 to get the transition you want.
Before I go, here is a scope shot of the circuit in action on the breadboard:
The output of the oscillator is in red, and the output of the one-shot (the servo control) is in yellow.
Tomorrow I'll build a permanent version.
pqe
edited 12-10-16 for minor cleanup