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.
Diff: AS5045Controller.cpp
- Revision:
- 1:2b21453e2c03
- Parent:
- 0:f2ebf8862df5
- Child:
- 2:02ea2289edb2
--- a/AS5045Controller.cpp Mon Sep 12 12:12:17 2016 +0000
+++ b/AS5045Controller.cpp Fri Sep 16 04:56:51 2016 +0200
@@ -0,0 +1,34 @@
+#include "AS5045Controller.hpp"
+
+AS5045Controller::AS5045Controller(PinName CS, int f, PinName D0, PinName CLK) :
+ _spi(NC,DO,CLK),
+ _cs(CS);
+{
+ _spi.format(9,2);
+ _spi.frequency(f);
+ _cs = 1;
+ _valid = false;
+}
+
+int AS5045Controller::Read()
+{
+ _cs = 0;
+ int upper = _spi.write(0x00);
+ int lower = _spi.write(0x00);
+ _cs = 1;
+
+ _magDEC = (lower >> 1) & 1;
+ _magINC = (lower >> 2) & 1;
+ _lin = (lower >> 3) & 1;
+ _cof = (lower >> 4) & 1;
+ _ocf = (lower >> 5) & 1;
+ _valid = (_ocf & !_cof & !_lin & (_magINC | _magDEC) );
+ _value = ((upper << 3)+(lower >> 6));
+
+ return _value;
+}
+
+bool AS5045Controller::IsValid()
+{
+ return _valid;
+}