Incremental Encoder

Description

On all modules equipped with at least two Digital inputs (DIN), it is possible to acquire signals from an incremental quadrature encoder using two channels, A and B. A software API allows you to read the number of revolutions, speed, angle, and pulse count.

Currently, reading the Z (index) signal is not supported by default. If needed, you can implement your own code to handle the Z signal alongside A and B.
The A and B signals are often provided as differential lines; connecting only the positive terminal will work.
However, for improved robustness—especially with long cables, it is recommended to use a differential line receiver before connecting the signals to the module.

Warning

Digital inputs include a low-pass analog filter with a cutoff frequency of 45 kHz. As a result, the maximum encoder frequency is limited. High-frequency or high-resolution encoders, or systems spinning very fast, may exceed this limit and not be read reliably.

Example of connection for an encoder

Characteristics

Encoder specifications

Requirements

Value

Remark

Voltage

5 - 30V

Maximum number of encoders

2

Code examples

The example code below demonstrates how to use an encoder with the OI-Stepper module:

/**
 * @file Encoder.cpp
 * @brief Encoder example using OpenIndus API
 * @author Kévin Lefeuvre (kevin.lefeuvre@openindus.com)
 * @copyright (c) [2025] OpenIndus, Inc. All rights reserved.
 * @see https://openindus.com
 */

#include "OpenIndus.h"
#include "Arduino.h"

OIStepper stepper;

void setup(void)
{
    printf("Hello OpenIndus!\n");
    stepper.encoder[0]->begin(DIN_1, DIN_2, 1024);
}

void loop(void)
{
    delay(1000);
    printf("Revolutions : %d | Pulses : %d | Angle : %.2frad | Speed : %.2fp/s\n", 
        stepper.encoder[0]->getRevolutions(),
        stepper.encoder[0]->getPulses(),
        stepper.encoder[0]->getAngle(),
        stepper.encoder[0]->getSpeed());
}

Software API

class Encoder

Public Functions

int begin(DIn_Num_t A, DIn_Num_t B, int16_t ppr)

Encoder initialization.

Parameters:
  • A – Digital input number A

  • B – Digital input number B

  • ppr – Pulse per revolution

Returns:

int

void end(void)

Encoder end.

void reset(void)

Reset the number of pulses and revolutions.

int getRevolutions(void)

Get the number of revolutions.

Returns:

int number of revolutions

int getPulses(void)

Get the number of pulses.

Returns:

int number of pulses

float getAngle(void)

Get the angle.

Returns:

float angle in radians

float getSpeed(void)

Get the speed.

Returns:

float speed in pulses per second