Main Content

Encoder

Measure rotation of motor in ticks

Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.

  • Encoder Arduino Motor Carrier block icon

Libraries:
Simulink Support Package for Arduino Hardware / Arduino Motor Carrier

Description

The Encoder block reads the position and rotational speed of the motor from an encoder that is connected to an MKR or Nano Motor Carrier. The position is measured in ticks, and the speed is measured in ticks per second. Every increment in the tick count indicates a clockwise rotation, and every decrement in the tick count indicates a counterclockwise rotation.

If you simulate a model that contains the Encoder block without connecting the hardware, the block outputs zeroes. For more information, see Block Produces Zeros or Does Nothing in Simulation.

Ports

Output

expand all

The Position port outputs the relative change in the position of the rotating motor, measured in ticks. For more information, see Calculate Position and Rotational Speed of the Motor.

Data Types: int32

The Speed port outputs the rotational speed of the motor, measured in ticks per second. For more information, see Calculate Position and Rotational Speed of the Motor.

Dependencies

The Speed port is available only when you select the Show Speed output port parameter.

Data Types: int32

Parameters

expand all

Select the channel number of the encoder that is connected to the MKR or Nano Motor Carrier.

When you select the Show Speed output port parameter, the Speed port becomes available. The port outputs the rotational speed of the motor, measured in ticks per second.

When you select the Reset count at initialization parameter, the block resets the tick count to 0 each time the Simulink® model runs on the hardware.

Specify how often the block reads the tick count from the encoder, in seconds. When you specify this parameter as -1, Simulink determines the best sample time for the block based on the block context within the model.

More About

expand all

Version History

Introduced in R2019a