Connecting an encoder to a VESC (AS5047, ABI): When, why, and how to configure it

An encoder measures the rotor's position with much greater precision than Hall sensors. On a VESC, it enables precise torque control at standstill, position control, and smooth operation at very low speeds. However, it requires careful mechanical installation and specific configuration, and it is only useful for certain machines. Here's what VESC Tool offers regarding encoders, how to configure them, and in what cases it's worth the effort.

The essentials

  • The type of encoder is selected in the Motor Settings, General tab, under the Sensors section, in the Sensor Port Mode parameter.
  • In FOC mode, you then select "Encoder" in the "Sensor Mode" section (on the "FOC" page).
  • An AS5047 encoder provides an absolute position reading as soon as it is powered on, while an ABI encoder must first find its index pulse.
  • The encoder detection measures three values: **Encoder Offset**, **Encoder Ratio**, and **Encoder Inverted**.
  • On most electric scooter motor-wheels, Hall sensors are almost always sufficient.

Encoder, Hall sensor, sensorless: what's the difference?

The Hall sensors integrated into most motors provide position information in 60-degree electrical increments. The VESC interpolates between these increments, which is more than sufficient to start a vehicle. An encoder provides continuous position information, with thousands of steps per revolution. Without a sensor, the controller estimates the position through calculation, which works well while moving but poorly when stationary. Our guide on Hall position sensors, encoders, and resolvers compares these technologies.

The VESC Tool help section accurately summarizes the uses: the encoder works well for position control applications, such as with a CNC milling machine; Hall sensors provide instant starts but are less suitable for position control.

The encoders offered by VESC Tool

The `Sensor Port Mode` parameter lists the sensors that the firmware can read. The most common ones are:

Sensor Port ModePrincipleImportant Note:
Hall sensorsThe Hall sensors of the motorThe default setting
ABI EncoderIncremental encoder with A, B, and index outputsNot applicable until the index is found; adjust the Encoder counts
AS5047 EncoderMagnetic encoder connected via SPIAbsolute positioning from the start, with some degree of non-linearity
AS5X47U Encoder (SPI)AS5147U or AS5247U, with safety featuresConnect to the COMM port; no application should use the UART, I2C, ADC2, or ADC3
Sin/Cos EncoderSine and cosine analog outputsSusceptible to interference: shielded cable and filtering
AD2S1205 ResolverResolver with conversion circuitSpecific equipment:

The list includes other models (MT6816, TLE5012, BISSC, etc.), which vary depending on the firmware version. The VESC Tool help documentation notes that this parameter has no effect as long as the motor is operating without a sensor.

The issue with the ABI encoder

An ABI encoder does not know its absolute position when powered on. According to the help documentation, the controller then operates in open-loop mode for one mechanical revolution to find the index pulse, during the first startup after each power-on. The Encoder counts parameter must be set: it is generally the encoder resolution multiplied by four, because each edge of both signals is counted.

The mechanical assembly

A magnetic encoder, such as the AS5047, reads a small magnet attached to the end of the rotating shaft. The chip itself remains stationary, facing the magnet and positioned centrally at a short distance. Any play or eccentricity translates into a positional error. This is relatively simple for a motor with a rotating shaft. However, in a scooter wheel motor, the axle is fixed, and it is the outer casing that rotates. Housing an encoder requires significant mechanical adaptation. This is one of the reasons why wheel motors often rely on Hall sensors.

Regarding wiring, the encoder connects to either the sensor port or the communication port, depending on the model and the board. Digital connections don't like long cables running alongside the phase wires: use short cables, shielded if possible, and keep them away from the power wires.

Adjusting settings in VESC Tool

  1. Choose the encoder in the "Sensor Port Mode" section and enter the configuration.
  2. Perform the FOC motor detection (resistance, inductance, flux) as usual: see our guide on FOC motor detection.
  3. Start the encoder detection process (refer to the help section Detect FOC Encoder Parameters). According to this help section, the motor rotates slowly in open-loop mode in both directions, completing one mechanical revolution, while the encoder is being read.
  4. Check the three results: **Encoder Offset** (the offset between the encoder's zero point and the motor's zero point), **Encoder Ratio** (the number of pole pairs for an encoder mounted directly on the shaft: 7 for a 14-pole motor, as indicated in the help), and **Encoder Inverted** (an encoder that counts in reverse).
  5. Apply, then select Encoder in the Sensor Mode section of the FOC page.

Beyond a certain speed, the controller can switch to sensorless mode: this is controlled by the Sensorless ERPM setting in the Encoder tab. To verify that the encoder and the observer are in agreement, the Realtime Data page provides a plot called Obs vs Enc: the difference between the estimated position and the measured position should remain small.

When the encoder is worth the effort

  • Position control: robots, arms, axes, servomechanisms. See our guide on VESC control modes.
  • Precise torque at zero speed and very low speeds: winches, mechanisms under load at startup.
  • Hall sensor-less motors and motors with insufficient saliency for HFI: please refer to our guide on HFI.

On electric scooters or light motorcycles, an encoder rarely provides a significant advantage over Hall sensors that are in good working order.

Workshop tip

A poorly mounted encoder is worse than having no sensor at all: a false position reading under load can cause jerking or a loss of torque. Pay attention to the mounting, the magnet centering, and the cable before adjusting any settings. For a robot or a special machine, our engineering department designs the complete motorization system, including the sensor, and sizes it for the machine. For a one-time intervention, our workshop charges by the hour (https://rage-mechanics.com/en/our-products/1529-labor-30-minutes.html).

Frequently Asked Questions

Do you need an encoder on a VESC-based scooter?

Almost never. The Hall sensors in the motor-wheel provide a clean start, and the observer takes over as the vehicle is moving. The encoder is used for precise position control or torque control when the vehicle is stationary.

What is the meaning of the "Encoder Ratio" setting?

For an encoder mounted directly on the motor shaft, this refers to the number of pole pairs of the motor. The encoder detects and measures this value.

Why is my ABI encoder not working at startup?

First, it needs to determine its index pulse. In the meantime, the controller operates in open-loop mode, making one mechanical revolution after each power-up.

The motor is not running correctly with the encoder. What should I check?

The mechanical assembly involves checking for play and ensuring proper alignment of the magnets. Next, the wiring needs to be checked, followed by re-running the encoder detection process. The "Obs vs. Enc" graph on the Realtime Data page indicates whether the measured position is consistent.