AS5048A SPI - Magnetic rotary encoder library
Library for communication over the SPI interface with the ams.com AS5048A magnetic rotary encoder.
Example:
Simple readout of a single angle measurement from a single sensor on the SPI-bus
#include "mbed.h" #include <as5048spi.h> // The sensors connection are attached to pins 5-8 As5048Spi sensor(p5, p6, p7, p8); Serial pc(USBTX, USBRX); // tx, rx int main() { while(1) { // const int* angles = sensor.read_angle(); int angle = angles[0]; // The read angle returns the value returned over the SPI bus, including parity bit pc.printf("Read result: %x\r\n", angle); if( As5048Spi::parity_check(angle) ) { // Convert range from 0 to 2^14-1 to 0 - 360 degrees int degrees = As5048Spi::degrees(angle)/100; pc.printf("Parity check succesfull.\r\n"); pc.printf("Angle: %i degrees\r\n", degrees ); } else { pc.printf("Parity check failed.\r\n"); } wait_ms(500); } }
The class supports daisy chaining multiple sensors on the SPI-bus as well. See: SPI-Daisy-Chaining.
Changes
Revision | Date | Who | Commit message |
---|---|---|---|
4:06b89a41109e | 2015-03-17 | JSpikker | Fixed documentation. |
3:a8ad32e439d4 | 2015-03-17 | JSpikker | Added documentation strings. |
2:2958500883e0 | 2014-12-04 | JSpikker | Added burst read functionality |
1:f2ed22514649 | 2014-09-18 | JSpikker | Default SPI clock frequency is now 1MHz |
0:3edcf58e51e7 | 2014-09-18 | JSpikker | Version 0.3: reads single sensor value, 10000 samples speed test at 10MHz SPI, writes data to local storage |