Alexandre Pirotte
/
AS5048
cc
Fork of AS5048 by
Revision 5:6b4cee1dd258, committed 2018-03-27
- Comitter:
- pirottealex
- Date:
- Tue Mar 27 13:27:06 2018 +0000
- Parent:
- 4:06b89a41109e
- Commit message:
- cc;
Changed in this revision
--- a/as5048spi.cpp Tue Mar 17 14:56:30 2015 +0000 +++ b/as5048spi.cpp Tue Mar 27 13:27:06 2018 +0000 @@ -1,11 +1,13 @@ #include "as5048spi.h" -As5048Spi::As5048Spi(PinName mosi, PinName miso, PinName sclk, PinName chipselect, int ndevices) : + +As5048Spi::As5048Spi(PinName mosi, PinName miso, PinName sclk, int ndevices) : _nDevices(ndevices), - _chipSelectN(chipselect), _spi(mosi, miso, sclk) { - _chipSelectN.write(1); + + //chip select à 1 + // AS5048 needs 16-bits for is commands // Mode = 1: // clock polarity = 0 --> clock pulse is high @@ -109,21 +111,25 @@ if(_nDevices == 1) { // Give command to start reading the angle - _chipSelectN.write(0); + //chip select à 0 + wait_us(1); // Wait at least 350ns after chip select _readBuffer[0] = _spi.write(command); - _chipSelectN.write(1); + //chip select à 1 + wait_us(1); // Wait at least 350ns after chip select } else { // Enable the sensor on the chain - _chipSelectN.write(0); + //chip select à 0 + wait_us(1); // Wait at least 350ns after chip select for(int i = 0; i < _nDevices; ++i) { _readBuffer[i] = _spi.write(command); } - _chipSelectN.write(1); + //chip select a 1 + wait_us(1); // Wait at least 350ns after chip select } return _readBuffer;
--- a/as5048spi.h Tue Mar 17 14:56:30 2015 +0000 +++ b/as5048spi.h Tue Mar 27 13:27:06 2018 +0000 @@ -25,7 +25,7 @@ class As5048Spi { public: - As5048Spi(PinName mosi, PinName miso, PinName sclk, PinName chipselect, int nDevices = 1); + As5048Spi(PinName mosi, PinName miso, PinName sclk, int nDevices = 1); ~As5048Spi(); bool error(int device = -1); @@ -76,7 +76,6 @@ protected: int _nDevices; - DigitalOut _chipSelectN; SPI _spi; int* _readBuffer; // Stores the results of the last sequential read
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 27 13:27:06 2018 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" +#include <as5048spi.h> +#define PI 3.1415926 + +// The sensors connection are attached to pins 5-8 +As5048Spi sensor1(p5, p6, p7,1); + + +Serial pc(USBTX, USBRX); // tx, rx +float vitesse,delta_deg,tour_sec; +int degrees_av,degrees; +Timer delta_t; + + +int main() { + pc.baud(38400); + delta_t.start(); + while(1) { + // + const int* angles = sensor1.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) ) + { + degrees = As5048Spi::degrees(angle)/100; + pc.printf("deg=%d\n\r", degrees); + // Convert range from 0 to 2^14-1 to 0 - 360 degrees + /*degrees_av=degrees; + degrees = As5048Spi::degrees(angle)/100; + delta_deg=(degrees-degrees_av); + if(delta_deg<0) + { + delta_deg=delta_deg+360; + } + tour_sec=((delta_deg)/delta_t.read())/(11*360); + vitesse=tour_sec*5.9*PI; + delta_t.reset(); + //vitesse=vitesse/(6.283185*11); + + pc.printf("vitesse=%0.2f m/sec \n\r",vitesse); + + //pc.printf("Parity check succesfull.\r\n"); + + //pc.printf("Angle: %i degrees\r\n", degrees );*/ + } + else + { + //pc.printf("Parity check failed.\r\n"); + } + + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Mar 27 13:27:06 2018 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6 \ No newline at end of file