While I wait for parts to arrive for another project, I have decided to fill the time by building a few common circuits that I have never really investigated, even though I know the theory.
One thing that I have never really investigated is the 555 timer chip, despite being a very common “jelly-bean” part. The circuit I built allows a you to control the position of a servo motor by turning a potentiometer – ie, a 50% turn of the potentiometer would result in (approximately) a 50% turn on the servo.
The first thing to understand is how a servo motor is controlled. While I am sure there are some slight variations between servos, the general idea is that you control it with PWM.
By sending pulses on the data wire of the servo, you can indicate the desired rotation by setting the correct length of pulse. A variation from about 0.5ms to 2.5ms should allow you to reach any rotation (again, servos may vary). The pulses are generally sent approximately every 20ms.
The question is, how do we generate these signals using a 555 and control it using a potentiometer.
(It is very important to note that there are circles at the output of the flipflop and input of the inverter – this means that the voltage at the base of the transistor is the inverse of the voltage at the output of the flipflop and the output voltage off the 555 is the same as the output voltage of the flipflop)
The first thing to realise is that everything in the dashed-box is actually inside the 555 timer – ie, a 555 is basically a potential divider, two comparators, a flipflop, an inverter and an NPN transistor.
Due to the potential divider inside the 555, the inverting input of the top comparator is held at approximately 3.33v (which is 2/3 of 5v) while the non-inverting input of the bottom comparator is held at 1.67v (which is 1/3 of 5v).
Next, note that the non-inverting input of the top comparator (pin 6) is connected externally to the inverting input of the bottom comparator (pin 2) and this is connected to C2. Let’s call the voltage at this point Vcp.
There are three distinct ranges of Vcp that we are interested in:
- Vcp < 1.67v: The top comparator is off and the bottom comparator is on. Therefore the R pin on the flipflop is low, and the S pin on the flipflop is high. Therefore the flipflop turns on.
- 1.67v < Vcp < 3.33v: Both comparators are off. Therefore both the R and S pins on the flipflop are low and the flipflop does not do anything.
- Vcp > 3.33v: The top comparator is on and the bottom comparator is off. Therefore the R pin on the flipflop is high and the S pin on the flipflop is low. Therefore the flipflop turns off.
The output of the flipflop can be seen at pin 3 of the 555 and is connected back to the middle terminal of the potentiometer.
The sequence of events that occurs to produce the pulses are as follows:
Let’s assume that initially Vcp = 1.66v and the flipflop is off (the 555 output voltage is the same as the flipflop output). This situation can be seen at the yellow dot in the screen shot above.
- Because Vcp is in Range 1, the flipflop turns on.
- With the flip flop on, the transistor is off (not conducting) and the output voltage is pulled high by R3. Because Vcp is 1.66v and pin 3 is at 5v, D2 begins to conduct and D1 does not conduct (as it is reverse biased). Therefore current flows from pin 3, through the potentiometer, through D2 and into C2. Therefore C2 charges and Vcp begins to increase and we enter Range 2 in which nothing happens to the flipflop.
- When Vcp reaches 3.34v, we enter Range 3 and the flipflop turns off.
- With the flipflop off, the transistor is on (conducting) and the output voltage is pulled low by the transistor. Because Vcp is at 3.34v and pin 3 is at 0v, D1 begins to conduct and D2 does not conduct. Therefore current flows from C2, through R1, through the potentiometer and into pin 3. Therefore C2 discharges and Vcp begins to decrease and we enter Range 2 in which nothing happens to the flipflop.
- When Vcp drops to 1.66v we are once again in the inital state and the process restarts.
The potentiometer changes the pulse length because it varies the resistance involved in charging and discharging C2. Turning it one way results in quicker charging and slower discharging. Turning it the other way results in slower charging and quicker discharging.
R1 increases the time taken for C2 to discharge and therefore results in pulses being sent less frequently. This is necessary because I found that my servo does not like being sent pulses too often. R1 does not affect charging as the current goes through D2 instead of D1.
C1 is not strictly necessary, but just holds the voltage at the inverting input of the top comparator at 3.33v more rigidly.