SMT, PCB Electronics Industry News

How to Use a Rotary Encoder

Aug 30, 2021

1. 如何使用扶轮编码器

旋转编码器、增量和 Oslash;20mm、2mm 轴、360 PPR、A、B、Z、5VDC

图像 1:自动扶轮编码器 E20S2-360-3-V-5-S



多转绝对编码器 10-30V

图片 2:P Ff 佩珀尔 - 富克斯编码器 Dsm58n - F3aagr0bn - 1213

使用旋转编码器的四种方法如下。

1.1 修改驱动程序

扶轮编码器是一种精密仪器。在使用过程中,它需要通过程序发布说明。需要根据不同情况的需要对驱动程序进行修改,从而确定编码器的效果。
在正常情况下,直接修改 reg 文件,并注册表文件,通过添加重写动态
链接。如果确定动态链接已修改,需要将其添加到内核中。

1.2 硬件接口连接

修改驱动程序后,硬件接口将连接。在连接中,通常有两个收集器输出接口 A 和

B。 为了确保线路连接,您需要使用 3.3V 电阻器操作。A 和 B 接口分别插入 CPU。
硬件接口成功连接后,检查电压输出终端的高低电压值是否
正确。例如,按下按钮后,如果 P2 端口产值较高,则是正确的。

1.3 编写流接口驱动程序

流接口驱动程序的编写是为了准备以下中断服务程序。具体的编写步骤是创建一个线程,以实现可变值的记录,同时记录在线路中断的情况下每个端口的价值是否仍然很高。

1.4 写作程序中断

最后一步是中断服务程序的编写。
使用旋转编码器的说明
如下:

 

* 确定可能是速度测量、距离测量、角位移或计数的检测对象。

* 它仅用于动态过程,或者它还包含静态位置或状态。

* 确认是选择增量旋转编码器还是绝对旋转编码器。

* 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.

2. 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.

3. How to Use an Incremental Encoder

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.

4. How to Use a Quadrature Encoder

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.



two square waveforms 90° out of phase

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.



interrupt output waveform is a square wave with twice the frequency

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.



the array of current and old value

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.

Dec 30, 2021 -

What does the Tire Pressure Sensor Fault Mean?

Dec 30, 2021 -

Car AC Compressor Troubleshooting-- Best Suggestions

Dec 29, 2021 -

Where is Servo Motor and Servo Drive Used?

Dec 29, 2021 -

Basics of Servo Motor You Should Know

Dec 28, 2021 -

How to Replace Refrigerator Compressor

Dec 28, 2021 -

When You Should Use an Absolute Encoder - Pros and Cons of Different Absolute Encoders

Dec 27, 2021 -

6 Reasons for Refrigeration Compressor Not to Start

Dec 27, 2021 -

Why Refrigeration Compressor Oil Deteriorates & How to Add Oil

Dec 26, 2021 -

Japanese Giant Mitsubishi Heavy Industries Goes Into Central Air Conditioners for Home Use

Dec 26, 2021 -

High Temperature Mulfunction of Screw Compressor and Solutions

92 more news from OKmarts Industrial Parts Mall »

Apr 16, 2024 -

I.C.T | Your One-Stop Service for Smart Meter SMT Factory

Apr 15, 2024 -

Three Industry Leaders Receive IPC President's Award

Apr 15, 2024 -

IFTEC's Pierre-Jean Albrieux Inducted into the IPC Raymond E. Pritchard Hall of Fame at IPC APEX EXPO 2024

Apr 15, 2024 -

IPC Honors Summit Interconnect and Robert Bosch GmbH with Corporate Recognition Awards

Apr 15, 2024 -

IPC Publishes Comprehensive Strategy to Address Electronics Industry's Global Workforce Challenge, Calls on Leaders in Government, Business and Education for Support

Apr 15, 2024 -

Data I/O Announces Major Milestone with 500th PSV System Sale Ahead of IPC APEX Expo

Apr 15, 2024 -

IPC Announces New Board Members at IPC APEX EXPO 2024

Apr 15, 2024 -

Seika Machinery Recognizes Outstanding Sales Achievements at 2024 IPC APEX EXPO

Apr 15, 2024 -

IPC Releases "J" Revisions to Two Leading Standards for Electronics Assembly

Apr 15, 2024 -

Altus Group Celebrates 30 Years of Innovation with Scienscope

See electronics manufacturing industry news »

How to Use a Rotary Encoder news release has been viewed 671 times

Facility Closure

Sell Your Used SMT & Test Equipment