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-dev-f303 FastPWM3
Diff: PositionSensor/PositionSensor.cpp
- Revision:
- 25:f5741040c4bb
- Parent:
- 23:2adf23ee0305
- Child:
- 26:2b865c00d7e9
diff -r 58c2d7571207 -r f5741040c4bb PositionSensor/PositionSensor.cpp
--- a/PositionSensor/PositionSensor.cpp Fri Apr 07 16:23:39 2017 +0000
+++ b/PositionSensor/PositionSensor.cpp Sun Apr 09 03:05:52 2017 +0000
@@ -26,9 +26,12 @@
void PositionSensorAM5147::Sample(){
cs->write(0);
raw = spi->write(readAngleCmd);
- raw &= 0x3FFF; //Extract last 14 bits
+ raw &= 0x3FFF; //Extract last 14 bits
cs->write(1);
- int angle = raw + offset_lut[raw>>7];
+ int off_1 = offset_lut[raw>>7];
+ int off_2 = offset_lut[((raw>>7)+1)%128];
+ int off_interp = off_1 + ((off_2 - off_1)*(raw - ((raw>>7)<<7))>>7); // Interpolate between lookup table entries
+ int angle = raw + off_interp; // Correct for nonlinearity with lookup table from calibration
if(angle - old_counts > _CPR/2){
rotations -= 1;
}