In this post we will add a second photointerrupter to our rotary encoder. This will give you information about the direction your rotary device turns. So you will be able to count forward and backword depending on the turning direction. This is necessary e. g. for many positioning application. The encoder we will make is also called a quadrature encoder.
How it works
We name the two photointerrupters A and B. The pulses are created the same way as with the simple rotary encoder from the last post. The picture shows the signal you want to get from your encoder. There is a phase shift of 90° between signal A and signal B. When you connect one of the signals to your counter you will have the simple rotary encoder again.
Now let’s have a closer look to how a counter works. It doesn’t count (=increase it’s value) when the signal is HIGH or LOW but at the moment the signal transits from one state to the other. The transition from LOW to HIGH is called the rising edge of the pulse, the transition from HIGH to LOW is called falling edge. Your counter counts either on the rising edge or the falling edge depending on how you initialize it. In this example it counts on the rising edge. We connect one of the signals to the counter, e. g. signal A. This gives us the pulses we count. The picture above shows that every time signal A has it’s rising edge (the moment the counter does it’s job) signal B is LOW.
The second picture shows the same rotary encoder but turning in the opposite direction. Now the phase shift between signal A and B is -90°. The counter input is still connected to signal A and it counts on rising edge of the signal. The picture shows that signal B is HIGH when signal A rises.
This is how it works: Take one of the signals A or B to give you the pulses you want to count. The other signal tells you the turnung direction. In the moment the counter has to change it’s value the signal is HIGH or LOW only depending on the direction of turn. This can tell the counter to count forward or backward.
How to build it
This is a upgrade of what we did with the simple rotary encoder. We take the same index disc but add a second photointerrupter.
We have to find a way to align both photointerrupters and adjust them to get the right phase shift. With photointerrupters that have mounting holes like the TCST 2103 you can easily do this on a piece of perfboard. Prepare it as shown on the picture. The holes are for the photointerrupter that can be adjusted. Saw or mill two long holes for the screws and a bigger one for the connectors.
One photointerrupter is fixed and will simply be soldered on the board. When soldering it you can tilt it to have it „look“ to the center of the index disc. This will give you a better signal.
Fix the second one with two screws in the long holes. Now the screws can slide in the holes and the connections are done with wires. You can adjust the photointerrupter by simply moving it up and down.
Bring the assembled board to your index disc and do the tests that are described in the photointerrupter details post. If you want to save energy connect both LEDs of the photointerrupters in series. Connect the outputs A and B to a scope and run your device. Having both signals on the screen you can bring the phase shift to 90° by moving the adjustable photointerrupter up and down in the long holes. When you don’t have a scope set the LED current to 20mA and connect two low power LEDs instead of the pullup resistors between OUT and Vcc. Turn your device slowly by hand and you will see the signals directly.
When everything is properly adjusted and fix you have your quadrature encoder ready. In the next post we will connect it to the arduino and look at the software. Furthermore there is an example of practical use: a winding machine.