Main Content

Quadrature Decoder

Compute position of quadrature encoder

Since R2020a

Libraries:
Motor Control Blockset / Sensor Decoders
Motor Control Blockset HDL Support / Sensor Decoders

Description

The Quadrature Decoder block computes the position of the quadrature encoder.

To calculate the angular position of the quadrature encoder (and the rotor) in either degrees, radians, or per-unit, the block uses one of the following methods.

  • Difference between current encoder counter value and encoder counter value at the previous index pulse (when index pulse is available).

  • Current encoder counter value (when index pulse is not available).

This figure shows a quadrature encoder disk with two channels (QEPA and QEPB) and an index pulse (QEPI):

In this example, the timer driven by the QEP increments by four for each slit:

Equations

The block computes the angular position (in counts) of the quadrature encoder as:

When the encoder rotates in the clockwise direction:

  • If IdxCnt,

    Position count=(CntIdx)

  • If Idx>Cnt and the shaft continues to rotate in the clockwise direction,

    Position count=(CntIdx)

  • If Idx>Cnt and the shaft starts rotating in the anticlockwise direction,

    Position count=Counts per revolution(IdxCnt)

When the encoder rotates in the anticlockwise direction:

  • If IdxCnt,

    Position count=Counts per revolution(IdxCnt)

  • If Idx<Cnt and the shaft continues to rotate in the anticlockwise direction,

    Position count=Counts per revolution(IdxCnt)

  • If Idx<Cnt and the shaft starts rotating in the clockwise direction,

    Position count=(CntIdx)

When you clear the External index count parameter, the Idx pulse resets Cnt to zero, therefore:

Position count=Cnt

where:

  • Position count is the angular position of the quadrature encoder in counts.

  • Counts per revolution is the number of counts in one rotation cycle of the quadrature encoder.

The block computes the output θm as:

Position=360×Position count/(Encoder slits×Encoder counts per slit) (in degrees)

Position=2π×Position count/(Encoder slits×Encoder counts per slit) (in radians)

Position=Cnt/(Encoder slits×Encoder counts per slit) (in per-unit)

Ports

Input

expand all

Value that the quadrature encoder counter generates with respect to the slit-position. The port only accepts a scalar unsigned integer based on the Counter size parameter. For example, if you select 8 bits for Counter size, the input data type must be uint8.

Data Types: uint8 | uint16 | uint32

Value that the quadrature encoder counter generated with respect to the slit-position at the time of the last index pulse. The port only accepts a scalar unsigned integer based on the Counter size parameter. For example, if you select 8 bits for Counter size, the input data type must be uint8.

Dependencies

To enable this port, select the External index count parameter.

Data Types: uint8 | uint16 | uint32

Note

The input data types for both Cnt and Idx must be identical.

Output

expand all

Angular position that the block computes based on the Cnt and Idx inputs.

Data Types: single | double | fixed point

Parameters

expand all

The number of slits available in each phase of the quadrature encoder.

The number of counts that the quadrature encoder generates for every slit. A count indicates a slit position. For example, select 4 (quadrature mode) if you want the encoder to generate four counts corresponding to 00, 10, 11, and 01 slit positions or values. If you select the quadrature mode:

Encoder density, in counts per revolution (post-quadrature) = Encoder counts per slit (4) ✖ Encoder slits

Counter size signifies the register size of the counter used by the processor to count the quadrature encoder pulses. It is the data type of the counter output of eQEP.

The block enables the Idx input port only if you select this parameter. The block expects that the Cnt input port value resets at the time of the Idx pulse.

Unit of the angular position output.

The data type for the angular position output.

Note

The Quadrature Decoder block may occasionally display the warning message 'Wrap on overflow detected.'

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced in R2020a