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.

History

Fixed documentation. default tip

2015-03-17, by JSpikker [Tue, 17 Mar 2015 14:56:30 +0000] rev 4

Fixed documentation.


Added documentation strings.

2015-03-17, by JSpikker [Tue, 17 Mar 2015 14:46:45 +0000] rev 3

Added documentation strings.


Added burst read functionality

2014-12-04, by JSpikker [Thu, 04 Dec 2014 10:00:42 +0000] rev 2

Added burst read functionality


Default SPI clock frequency is now 1MHz

2014-09-18, by JSpikker [Thu, 18 Sep 2014 19:28:25 +0000] rev 1

Default SPI clock frequency is now 1MHz


Version 0.3: reads single sensor value, 10000 samples speed test at 10MHz SPI, writes data to local storage

2014-09-18, by JSpikker [Thu, 18 Sep 2014 10:20:22 +0000] rev 0

Version 0.3: reads single sensor value, 10000 samples speed test at 10MHz SPI, writes data to local storage