Tutorial How to U tutorial-how-to-use-a-quadrature-encoderse a Quadrature Encoder Rs011a

Embed Size (px)

DESCRIPTION

tutorial-how-to-use-a-quadrature-encoder

Citation preview

  • 7/21/2019 Tutorial How to U tutorial-how-to-use-a-quadrature-encoderse a Quadrature Encoder Rs011a

    1/3

    How to use a quadrature encoder

    A quadrature encoder, also known as an incremental rotary encoder measures the speed and direction ofa rotating shaft. Quadrature encoders can use different types of sensors, optical and hall effect are both

    commonly used. The photo shows inside of a Rover 5 gearbo. There are two !R sensors on the "#$

    that look at the black and white pattern on one of the gears. %o matter what type of sensors are used the

    output is typically two square waveforms &'( out of phase as shown below.

    !f you only wish to monitor the speed of rotation then you can use either output and simply measure the

    frequency. The reason for having two outputs is that you can also determine the direction of shaftrotation by looking at the pattern of binary numbers generated by the two outputs.

    )epending on the direction of rotation you will get either*

    '' + '

    ' +

    + -

  • 7/21/2019 Tutorial How to U tutorial-how-to-use-a-quadrature-encoderse a Quadrature Encoder Rs011a

    2/3

    ' +

    or

    '' + '

    ' +

    + - ' +

    $y feeding both outputs into an /0R gate 1eclusive 0R2 you will get a square wave with twice the

    frequency regardless of direction. This can be useful as it allows one interrupt pin to monitor both

    encoder inputs.

  • 7/21/2019 Tutorial How to U tutorial-how-to-use-a-quadrature-encoderse a Quadrature Encoder Rs011a

    3/3

    ! was looking at how to write efficient code to convert these binary inputs into a simple 3forward or

    backward3 output. ! ended up with a dimensional array 1matri2 that made the code quick and easy.

    The binary values above convert to ',,-, or ',,-, depending on the direction. This pattern repeats

    continuously. $y using the current value from the encoder to inde one dimension of the array and theprevious value to inde the other dimension you can quickly get a 4, ', or output. 6y array looks

    like this.

    As you can see, if the value has not changed then the output is '.

    The sequence of ', , -, gives an output of 4.The sequence of ', , -, gives an output of .

    / represents a disallowed state and would most likely occur if the encoder outputs are changing too

    quickly for your code to keep up. %ormally this should not happen. !n my code ! put a here. 7hen !

    get an output of ! know that ! got an error, perhaps due to electrical noise or my code being too slow.!f you replace / with ' then the disallowed state will be ignored.

    !n my Arduino code ! make this a dimensional array. that looks like this*

    int Q86 9:; + ?? Quadrature 8ncoder 6atri

    To read the array my inde is* 0ld @ %ewBo my code reads like this*

    0ld + %ew>%ew + digitalRead 1inputA2 @ digitalRead 1input$2> ?? #onvert binary input to decimal value

    0ut + Q86 90ld @ %ew;>

    Cood luck and enDoy.

    $rought to you by http*??letsmakerobots.com