Using the AS5145B Magnetic Encoder with the FRC Control System
This article details how to use the Austria Microsystems AS5145B Magnetic Encoder (FIRST Choice P/N fc-13-062) with the FRC Control System
Sensor Overview
The Austria Microsystems AS5145B Rotary Position Sensor (FIRST Choice P/N fc13-062) is a contactless magnetic rotary position sensor. This sensor has 2 absolute outputs (a serial interface, and a PWM output) and a 12 bit incremental output quadrature A/B and Index mode. The easiest mode of the sensor to interface with the FRC system is the incremental quadrature A/B output. In this mode the sensor will output a quadrature signal on the A and B outputs that is compatible with the Encoder class/VIs of WPILib.
Wiring The Sensor
To wire the sensor to the FRC Control System, the following connections must be made:
- The pin labeled 5V on the sensor should be connected to a 5V (labeled "PWR") pin of the Digital Sidecar Digital I/O bank
- The 2 pins labeled GND should be connected to a ground pin (labeled "(-)") on the Digital Sidecar.
- The pins A and B should be connected to separate signal pins (labeled "SIG") on the Digital Sidecar.
- The pin CSn should be connected to a ground pin on the Digital Sidecar (for a description of the purpose of this pin, see "Incremental Power-up Lock Option" on Page 15 of the datasheet
- Optional - The MAG DECn and MAG INCn pins may be connected to signal pins on the Digital Sidecar. These pins provide information about the strength of the magnetic field and are particularly helpful when positioning the magnet and/or sensor. If connected to separate inputs these pins will behave as described in Table 9 of the datasheet. It is also possible to connect both pins to a single input, in which case the signal will be high when the magnetic field is in range and low otherwise. Note: The Digital Sidecar has built-in pull-up resistors so no additional pull-up resistor should be required. Note 2: These pins are active low pins meaning that a value of "Off" in the table indicates a high (5v) signal at the Digital Sidecar and a value of "On" indicates a low (~0V) signal at the Digital Sidecar.
Positioning the Magnet
Details on the magnet placement can be found in Section 9.4.2 of the datasheet. The summary of that section is that the magnet should be centered over the chip package and located between .5mm and 1.5mm away from the package. Monitoring the MAG DECn and MAG INCn pins (by sending the data to the Dashboard for example) may help in positioning the magnet/sensor.
Writing the Code
After the magnet and sensor have been positioned this sensor may be treated the same as any other quadrature encoder in software. The AS5145B is the equivalent of an optical encoder with a 1024 count disc, meaning it will output 1024 pulses per channel per revolution. In 4x decoding mode, this will yield 4096 ticks per revolution.
Using the AS5145B as an absolute sensor
There are two absolute outputs of the AS5145B sensor. The easier of the two to use with the FRC Control System is the PWM output. The PWM output can be converted to an analog output using a simple low pass filter. A diagram of an appropriate low pass filter circuit, as well as recommended component values can be found on page 18 of the datasheet. Once an analog signal is obtained, this signal can be connected to a channel on the Analog Breakout board and read using the Analog Channel class/VIs.
The other absolute output of the AS5145B is an SSI (Synchronous Serial Interface) which is also known as SPI (Serial Peripheral Interface). Interfacing with this output may be possible by using the SPI class/VIs though FRC has not attempted to use this output with the FRC Control System.