A rotary encoder converts the angular position or motion of a shaft or axle to 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 which require monitoring or control, and mechanical systems. So how to use a rotary encoder?
Image 1: Autonics Rotary Encoder E20S2-360-3-V-5-S
Image 2: P+F PEPPERL+FUCHS Encoder DSM58N-F3AAGR0BN-1213
The four methods of using a rotary encoder are as follows.
Rotary encoder is a precision instrument. It needs to issue instructions through the program during its use. Driver need to be modified according to the needs of different situations, which determines 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.
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 the 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.
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.
The last step is to interrupt the writing of service program.
The instructions of 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.
*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.
An incremental encoder converts angular motion or position of a shaft into an analog or digital code to identify position or motion. Incremental encoders are one of the most commonly used rotary encoders.
*Incremental rotary encoders with different resolutions which are measured by the number of pulses, ranging from 6 to 5400 or higher generated per resolution. The more pulses, the higher the resolution. It is an important basis for selection.
*There are usually three signal outputs of incremental encoders (six signals for differential): A, B and Z, generally using TTL level, A pulse in the front, B pulse in the back. A and B pulses are 90 degrees apart. Each circle sends out a Z pulse, which can be used as a reference mechanical zero position. Generally, judge the direction by determining A is ahead of B or B is ahead of A.
*If PLC is used to collect data, high-speed counting module can be chosen; if industrial computer is used, choose high-speed counting board; if single-chip microcomputer is used, choose input port with photocoupler.
*It is recommended that B pulse be forward, A pulse should be reverse, and Z origin zero pulse.
*Set up a counting stack in the electronic device.
A quadrature encoder measures the speed and direction of a rotating shaft. It is called an incremental rotary encoder. Different types of sensors are used, in which optical and hall effect are both common.
In the picture, it shows that there are two IR sensors on the PCB inside a Rover 5 gearbox. The sensors look at the black and white pattern on one of the gears. No matter what type of sensors are used the output is typically two square waveforms 90° out of phase as shown below.
Image 3: The output waveform of phase
You can use either output and simply measure the frequency to monitor the speed of rotation. There are two outputs, so you can determine the direction of shaft rotation by looking at the pattern of their binary numbers.
Depending on the direction of rotation you will get either:
00 = 0
01 = 1
11 = 3
10 = 2
or
00 = 0
10 = 2
11 = 3
01 = 1
By feeding both outputs into an XOR gate (exclusive OR) you will get a square wave with twice the frequency regardless of direction. It allows one interrupt pin to monitor both encoder inputs.
Image 4: The waveform of phase
Look at how to write efficient code to convert these binary inputs into a simple "forward or backward" output.
A 2 dimensional array (matrix) that made the code quick and easy. The binary values above convert to 0,1,3,2 or 0,2,3,1 depending on the direction, which repeats continuously.
Index one dimension of the array and the previous value to index the other dimension by using the current value from the encoder, then you can quickly get a -1, 0, or +1 output. The array looks like this.
Image 5: A 2 dimensional array
So, if the value has not changed, the output will be 0. The sequence of 0, 1, 3, 2 gives an output of -1. The sequence of 0, 2, 3, 1 gives an output of +1.
X represents a disallowed state and would most likely occur if the encoder outputs are changing too quickly for your code to keep up. Normally this should not happen. When there is an output of 2, an error occurs, perhaps due to electrical noise or the code being too slow.
If you replace X with 0 then the disallowed state will be ignored.
If you make this a 1 dimensional array:
int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0}; // Quadrature Encoder Matrix
To read the array the index is: Old * 4 + New
So the code reads like this:
Old = New;
New = digitalRead (inputA) * 2 + digitalRead (inputB); // Convert binary input to decimal value
Out = QEM [Old * 4 + New];
Hope the above information is helpful to you anyway.
10/16/2021
A rotary encoder converts the angular position or motion of a shaft or axle to analog or digital output signals, so it is also called a shaft encoder. Absolute encoder and incremental encoder are the two main types.
10/14/2021
As both manufacturers and end customers know, in a refrigeration or air conditioning system, the compressor is the equipment core by continuously sucking back and exporting refrigerant
10/14/2021
In a series of modern machinery industries like construction, building materials, mining, engineering vehicles, metallurgy, water conservancy, port machinery and other fields related to large heavy equipment, the reliability and safety of equipment comes first in process control.
10/13/2021
When mentioning refrigeration, everyone in this modern world may be familiar with it. People's daily use of air conditioners, refrigerators, whether small household or large commercial ones, are refrigeration appliances.
10/12/2021
The larger the setting value, the higher the gain and the greater the stiffness. Under the same frequency command pulse condition, the position lag will be smaller.
03/18/2021
The servo drives, the motor under the command signal from a control system, so whether the drive can work normally or not directly affects the overall performance of the equipment. In the servo control system, the servo drive is equivalent to the brain, and the servo motor is equivalent to the hands and feet.
03/18/2021
According to the current of the motor, use a driver that is greater than or equal to this current. If low vibration or high precision is required, a subdivision drive can be used. For high-torque motors, use high-voltage drivers as much as possible to obtain good high-speed performance.
03/18/2021
The larger the setting value, the higher the gain and the greater the stiffness. Under the same frequency command pulse condition, the position lag will be smaller.
03/17/2021
When the vertical machining center supporting FANUC6 system is working, the machine tool vibrated severely, and the AC spindle drive displayed AL-04 alarm. During the vertical machining center supporting FANUC6 system is working, the machine tool vibrates severely, and the AC spindle drive displays AL-04 alarm.
03/17/2021
The high-speed performance of the motor depends on the power supply voltage, the output torque of the motor on the current setting value.
IWAYA DENKI Water Pump 25CJT0752
Panasonic Servo Motor MHMF022L1V2M
Honeywell Solenoid Valve VE4025B1045
ROTEN Mechanical Seal 8E5K-22-X
UNIVER Solenoid Valve AG-3100
Omega Flowmeter FMA-4102
DANHI Air Cylinder SCA2B50-200
Siemens Resistor 853 01 15R0 + -20%
AirTAC Air Cylinder SE32X575S