How to Use a Rotary Encoder?

Henry Jennings
3 min readJun 20, 2021

A rotary encoder converts the angular position or motion of a shaft or axle to an analog or digital output signals, so it is also called a shaft encoder. Absolute encoder and incremental encoder are the two main types. Rotary encoders are applied widely, including situations that require monitoring or control, and mechanical systems. So how to use a rotary encoder?

  1. How to Use a Rotary Encoder

The four methods of using a rotary encoder are as follows:

  • Modify the Driver

The rotary encoder is a precision instrument. It needs to issue instructions through the program during its use. Driver needs to be modified according to the needs of different situations, which determines the encoder’s effect.

Under normal circumstances, modify the reg file directly, and register a table file, rewrite the dynamic link through adding. In the case where it is determined that the dynamic link has been modified, it needs to be added to the kernel.

  • Hardware Interface Connection

After the driver is modified, the hardware interface will be connected. In the connection, there are usually two collector output interfaces A and B.

In order to ensure line connectivity, you need to operate on a 3.3V resistor. A and B interfaces are plugged into the CPU respectively.

After the hardware interface is successfully connected, check whether the high and low voltage values of the voltage output terminal are correct. For example, after pressing the button, if the P2 port output value is high, it is correct.

  • Writing the Stream Interface Driver Program

The writing of the stream interface driver is to prepare for the following interrupt service program. The specific writing step is to create a thread to realize the record of the variable value, and at the same time record whether the value of each port is still high in the case of a line interruption.

  • Interruption of Writing Program

The last step is to interrupt the writing of the service program.

The instructions for using rotary encoders are as follows:

  • Determine the detection object that may be speed measurement, distance measurement, angular displacement or counting.
  • It is only used for dynamic process, or it also contains static position or state.

-Confirm whether to choose incremental rotary encoder or absolute rotary encoder.

  • Determine the range of motion of the object.
  • Confirm whether to select a single-turn or multi-turn absolute rotary encoder.
  • Determine the maximum speed or frequency of the object.
  • Determine the accuracy required of the object.
  • Determine the application parameters of the rotary encoder.
  • Using environment. Pay attention to the interface mode and protection level of the rotary encoder.
  1. Precautions of Using a Rotary Encoder

*Vibration applied to the rotary encoder will often cause false pulses. Therefore, the installation location is very important. When the number of pulses generated per revolution is larger, and the slot interval of the rotating grooved disc is narrower, the more susceptible it is to vibration. While rotating or stopping at a low speed, the vibration added to the shaft or body of the encoder makes the rotary grooved disc jitter, and false pulses may occur at any time.

*Note the polarity of the power supply when wiring the encoder. If the wiring is wrong, the internal circuit of the encoder may be damaged.

*Wiring should be done when the power supply is OFF. When the power supply is on, if the output line contacts the power supply, the encoder output circuit may be damaged.

*In order to avoid encoder induced noise, try to use the shortest circuit, especially when there is input to an integrated circuit.

--

--

Henry Jennings

I made this blog to express myself on certain issues that bother me with the hope of impacting others, I haven’t always been strong emotionally. www.henry556.co