Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Watchdog stm32-sensor-base2
Diff: AS5045/AS5045.cpp
- Revision:
- 4:f6e22dd39313
- Parent:
- 1:3c6771928b35
- Child:
- 5:97117a837d2c
--- a/AS5045/AS5045.cpp Tue Jul 07 15:02:22 2020 +0000 +++ b/AS5045/AS5045.cpp Sat Jul 18 14:59:04 2020 +0000 @@ -1,5 +1,5 @@ #include "AS5045.h" - +//we have 5040 /** Constructor * * @param CS Pin number for the digital output @@ -7,16 +7,18 @@ * @note * PinName CS is the digital output pin number */ + + + Timer timer_enc; AS5045::AS5045(PinName CS) : _spi(NC,D12, D13), // MBED SPI init _cs(CS) // Digital output pin init { // Set SPI bitwidth - _spi.format(9,2); + _spi.format(9, 2); // Set SPI frequency - _spi.frequency(SPI_FREQ); - + _spi.frequency(50000);//SPI_FREQ); // Set the digital output high _cs = 1; } @@ -28,21 +30,29 @@ */ int AS5045::getPosition() { - int upper, // Upper part of the tick amount integer - lower; // Lower part of the tick amount integer + unsigned int upper, // Upper part of the tick amount integer + lower; // Lower part of the tick amount integer // Set the chip select pin low _cs = 0; - + timer_enc.reset(); + timer_enc.start(); + wait_ms(5); // Read data from the encoder - upper = _spi.write(0x00); - lower = _spi.write(0x00); + upper = (_spi.write(0x00)) ; + lower = (_spi.write(0x00)); + +// lower = lower >> 6; +// upper = (upper >> 6)+lower; +// upper = upper & 0xffc0; + upper = upper >> 6; // Set the chip select pin high _cs = 1; - +wait_ms(5); // Return full 9-bits tick amount - return ((upper << 3)+(lower >> 6)); + return upper; + //return upper ; } /** Convert position of the encoder to degrees