A blog documenting projects and ideas

They are used to add position feedback to things that move in a linear way. For example, printers and scanners. Some printers use DC motors with strip encoders as opposed to stepper motors. The reason for this likely because DC motors are cheaper than steppers.

The printer parts used in this project were taken from a combined printer/scanner machine. It contained two of these encoders. The encoder from the scanner was experimented on in order to try and figure out the pinout of the device. The encoder consisted of two parts, a red led and a photosensitive transistor. The LED pinout was the easy part, just guess which is positive and which is negative, if that doesn’t work, switch the power cables. The slightly more tricky part was the encoder. It had four pins coming out of it. After guessing that two of these pins were for power ( positive and negative ) the other two pins are signal pins. The likely reason why there are two pins is for a thing called quadrature feedback. This allows the direction to be determined from the phase of the pulses.

How position is determined from the above picture is as follows. In the above picture, on the rising edge of A, is B high or low? Is B a 1 or a 0? Whether the encoder strip is moving left or right will determine that answer to that. You can see in the picture in one direction B will be high on the rising edge of A, in the other direction it will be a zero.

For the purposes of this project, ( controlling the position of a printer head ) only one channel is needed. This is because the direction of the printer head will be determined by the microcontroller at all times. The output from the encoder becomes a simple single square wave like in the image below.

These pulses are easily read by the microcontoller. The pulses were read into the microcontroller using interrupts. In this case, as soon as a falling edge is detected on the external interrupt pin int0, the microcontroller jumps to an interrupt service routine (ISR). This routine simply increments a counter by 1. See the code related to the ISR below: