DigiKey-eMag-Sensors-Vol 19

Arduino sample code for SPI absolute encoders

Listing 7: Reading the encoderPosition and the turns counter in a multi-turn AMT22 encoder.

To avoid communication with the encoder during this reset period, a delay of 250 ms is implemented, ensuring that no commands are sent to the encoder during its power-on time. While it is possible for the code to set the zero position of the encoder at the beginning of operation, it is more common in typical applications to set the zero position only once during the initial configuration of the device for use within the system. This practice helps maintain the integrity of the encoder's position feedback throughout its operational lifespan.

the position and the turn count in a single data retrieval sequence. If the position data received is invalid, the system should notify the user of the error. In contrast, if the position is valid, the program should report the position in decimal format (Listing 7). This capability enhances the encoder's functionality by providing comprehensive feedback on both the absolute position and

the number of complete turns, facilitating more accurate monitoring and control in applications requiring precise rotational data. Running the code With the code successfully created, it’s time to upload it to the Arduino and establish communication with the AMT22 encoder.

Read turns counter (multi-turn only)

Certain variants of the AMT22 encoder support a multi-turn counter, allowing users to read both

Figure 3: The reported position from the encoder, received by the Arduino (Image source: Same Sky)

52

Powered by