Skip to main content
The VESC firmware supports ten encoder driver families, each implemented as a standalone module under encoder/. All drivers expose at minimum an init, deinit, and angle-read function. The encoder core in encoder.c selects and wraps the active driver based on the motor configuration. The active driver is identified by the encoder_type_t enum defined in encoder_datatype.h:

ABI — enc_abi

ABI (A/B/Index) is the standard incremental quadrature encoder interface. Channels A and B produce 90°-offset square waves; counting transitions gives position. The optional Index (I) pulse fires once per revolution and is used to establish an absolute reference. Key state fields (ABI_state):
Call encoder_index_found() to check whether the firmware has seen the index pulse after power-on. FOC accuracy improves once the index is found.

AS504x — enc_as504x

The AS504x family (AS5040, AS5045, AS5047, AS5048) from ams-OSRAM are contactless magnetic rotary position sensors that communicate over SPI using a bit-bang software SPI (spi_bb). Diagnostic fields (AS504x_diag):
Monitor is_COF, is_Comp_low, and is_Comp_high to verify correct airgap between the sensor and the diametrically magnetised target magnet.

AS5x47U — enc_as5x47u

The AS5x47U family (e.g., AS5047U, AS5147U) are high-speed magnetic rotary encoders from ams-OSRAM with hardware SPI and an extended diagnostic register set. Diagnostic fields (AS5x47U_diag) include watchdog test status (is_wdtst), CRC error flag (is_crc_error), broken Hall flag (is_broken_hall), and field half-strength flag (is_mag_half), in addition to the same AGC and magnitude fields as the AS504x.

BiSS-C — enc_bissc

BiSS-C (Bidirectional Serial Synchronous Communication) is an open-standard serial interface for absolute encoders and other sensors. The firmware uses hardware SPI and a 6-bit CRC to validate each frame. Key state fields (BISSC_state):

MA782 — enc_ma782

The MagAlpha MA782 from Monolithic Power Systems is a high-speed contactless angle sensor with an SPI interface and an internal angle tracking register. The driver uses an asynchronous state machine (ma782_substate_t) with MA782_IDLE and MA782_READ_ANGLE_REQ states to pipeline SPI transfers with the FOC interrupt. Error flags (ma782_error_t):

MT6816 — enc_mt6816

The MT6816 from MagnTek is a 14-bit contactless magnetic angle sensor with hardware SPI and a no-magnet detection flag. Key state fields (MT6816_state):
Non-zero encoder_no_magnet_error_cnt indicates the target magnet is missing or the airgap is too large. Do not run FOC in this condition.

PWM — enc_pwm

Some encoder and position-sensor modules output angle as a PWM duty cycle (e.g., AS5600 in PWM mode). The enc_pwm driver captures the duty cycle using a timer input-capture peripheral and converts it to degrees. The ENCODER_TYPE_PWM_ABI variant combines PWM absolute position with ABI quadrature for higher update rates.

SinCos — enc_sincos

Analogue sine/cosine encoders output two 90°-phase-shifted analogue signals. The firmware reads these on ADC channels, applies gain and offset calibration, and computes the angle with atan2. Configuration (ENCSINCOS_config_t) exposes gain (s_gain, c_gain), offset (s_offset, c_offset), a low-pass filter_constant, and a phase_correction angle to compensate for mechanical misalignment between the sine and cosine tracks.

TLE5012 — enc_tle5012

The TLE5012B from Infineon is a magnetic angle sensor with a proprietary SSC (Synchronous Serial Communication) interface that is compatible with software SPI. Error types (tle5012_errortypes):

TS5700N8501 — enc_ts5700n8501

The TS5700N8501 from Tamagawa Seiki is a serial absolute encoder commonly found on industrial servo motors. It communicates over a UART-based serial interface and provides both single-turn and multi-turn (ABM) position. The multi-turn counter is readable via enc_ts5700n8501_get_abm() and can be reset with enc_ts5700n8501_reset_multiturn().
The TS5700N8501 runs its communication in a dedicated ChibiOS thread due to the UART timing requirements. The raw 8-byte status frame is available at cfg.state.raw_status for advanced diagnostics.

Implementing a custom encoder

If none of the built-in drivers match your hardware, the encoder system supports a custom callback interface:
Set encoder_type_t to ENCODER_TYPE_CUSTOM in the motor configuration and register your three callbacks. The FOC loop will call read_deg() on every current-control cycle.