external primary encoders for moteus

With the r4.8 release of moteus, a not-yet-announced feature was included — the ability to have an off-board primary encoder! It didn’t get announced at the time, because the connectors necessary to populate the board were not obtainable. In fact, that is still the case, but I’ve located a substitute part which works well enough, so here we go!

Theory

The moteus controller uses an absolute magnetic encoder to determine the relationship between the rotor and stator of the motor at each given instant. That allows it to produce torque in the motor at any speed, from standstill to the maximum possible speed. Until now, the only magnetic encoder that was supported is the one mounted to the backside of the board. This is largely acceptable, as moteus is intended to be used in integrated applications.

However, some users like the moteus form factor and capabilities, but don’t have room to put the entire board right next to the sense magnet. Now the pads on the back can be used for just that:

These pads contain SPI signals that can be optionally configured to enable an external primary encoder. As of now, the only encoder IC supported is the same one that is mounted on the board, the AS5047P (or anything with an identical SPI protocol).

Usage

To use this mode, you need to connect the external AS5047P IC to the pads on the back of moteus. You can do that with either connectors, or by soldering bare wires to the pads. The following connector set is in stock at Digi-Key as of 2022-03-07 and is compatible:

Additionally, Digi-Key stocks a breakout board for the AS5047P, with which slight modification can be used:

To use this, you need to position the jumper to connect the 3.3V supply as the primary source. In my example here, I pulled out the pins and soldered a bridge across it so it could fit flush against a motor.

AS5047P breakout configured for 3.3V

Finally, you need to enable the external encoder in configuration:

  • encoder.mode – Set to 1 for an external AS5047 SPI compatible encoder

At this point, the motor can be calibrated as usual.

Limitations

As moteus uses a high bit-rate for SPI (12Mhz), the allowable connection length is short, <20cm is recommended. The wires will be somewhat sensitive to interference, so the allowable length may be even shorter for environments with large amounts of EMI.

While encoders other than the AS5047 may be supported in the future, the possibilities are somewhat limited due to the way moteus samples the encoder currently.

Video

Here’s a video showing all this put together: