Connection between microcontroller and incremental rotary encoder

Publisher:明石轩Latest update time:2016-08-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The incremental rotary encoder converts the timing and phase relationship of its angle code disk through two internal photosensitive receiving tubes to obtain the increase (positive direction) or decrease (negative direction) of the angle displacement of its angle code disk. After combining with digital circuits, especially single-chip microcomputers, the incremental rotary encoder has the advantages of being cheaper and simpler in angle measurement and angular velocity measurement than the absolute rotary encoder.

   Points A and B correspond to two photosensitive receiving tubes, the distance between points A and B is S2, and the grating spacing of the angle code disk is S0 and S1 respectively.

When the angle encoder rotates at a constant speed, the ratio of S0:S1:S2 in the output waveform is the same as the ratio of S0:S1:S2 in the actual graph. Similarly, when the angle encoder rotates at other constant speeds, the ratio of S0:S1:S2 in the output waveform is the same as the ratio of S0:S1:S2 in the actual graph. If the angle encoder performs variable speed motion, it is considered as a combination of multiple motion cycles (defined below), then the ratio of S0:S1:S2 in the output waveform in each motion cycle is still the same as the ratio of S0:S1:S2 in the actual graph.

From the output waveform, we can see that the timing of each motion cycle is

Clockwise movementCounterclockwise movementAB 
AB

1 1                                11

0 1                                10

0 0                                 00

1 0                                 01

We save the current A and B output values ​​and compare them with the next A and B output values ​​to easily get the movement direction of the angle encoder.

If the grating grid S0 is equal to S1, that is, the radian angle of S0 and S1 is the same, and S2 is equal to 1/2 of S0, then the displacement angle of the angular encoder movement is 1/2 of the radian angle of S0, and divided by the time consumed, the angular velocity of the angular encoder movement is obtained.

When S0 is equal to S1, and S2 is equal to 1/2 of S0, the movement direction and displacement angle can be obtained in 1/4 movement cycle. If S0 is not equal to S1, and S2 is not equal to 1/2 of S0, then 1 movement cycle is required to obtain the movement direction and displacement angle. Here

is a mechanical rotary encoder detection program written in 51.  
#define WA = PX.X 
#define WB = Py.y 

void encoder(void) 
{  
    unsigned char i,j; 
    static unsigned char ta,tb; 
    TR1 = 0; 
    i = WA; 
    j = WB; 
     
    if((i^j)&&(ta&tb)) 
    { 
        if((i == 1)&&(j ==0)) 
        { 
            count++; 
        } 
        else if((i == 0)&&(j == 1)) 
        { 
            count--; 
        } 
    }
Reference address:Connection between microcontroller and incremental rotary encoder

Previous article:Several necessary steps to learn MCU in depth
Next article:The difference between MCU in-circuit emulator and in-circuit programmer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号