TLE5012B  3.1.0
The TLE5012B is a pre-calibrated 360° angle sensor that detects the orientation of a magnetic field. The raw signals (sine and cosine) are digitally processed internally to calculate the angle orientation of the magnetic field (magnet).
TLE5012b.hpp
Go to the documentation of this file.
1 
14 #ifndef TLE5012B_HPP
15 #define TLE5012B_HPP
16 
17 #include <string.h>
18 #include "../pal/gpio.hpp"
19 #include "../pal/spic.hpp"
20 #include "tle5012b_util.hpp"
21 #include "tle5012b_reg.hpp"
22 
29 class Tle5012b
30 {
31  public:
32 
39  enum slaveNum
40  {
41  TLE5012B_S0 = 0x0000,
42  TLE5012B_S1 = 0x2000,
43  TLE5012B_S2 = 0x4000,
44  TLE5012B_S3 = 0x6000
45  };
46 
48  GPIO *en;
49  Reg reg;
51 
52  struct safetyWord {
53  bool STAT_RES;
54  bool STAT_ERR;
55  bool STAT_ACC;
56  bool STAT_ANG;
57  uint8_t RESP;
58  uint8_t CRC;
59 
65  return (RESP == 0x7 ? TLE5012B_S3
66  : (RESP == 0xB ? TLE5012B_S2
67  : (RESP == 0xD ? TLE5012B_S1
68  : TLE5012B_S0)));
69  }
70 
76  uint16_t fetch_Safety(uint16_t reg)
77  {
78  CRC = (reg & 0x7F);
79  RESP = (reg & 0xF00) >> 8;
80  STAT_ANG = (reg & 0x1000) >> 12;
81  STAT_ACC = (reg & 0x2000) >> 13;
82  STAT_ERR = (reg & 0x4000) >> 14;
83  STAT_RES = (reg & 0x8000) >> 15;
84  return (reg);
85  }
86  } safetyWord_t;
87 
89  Tle5012b();
90 
92  ~Tle5012b();
93 
96 
103  errorTypes begin(uint8_t csPin, slaveNum slave=TLE5012B_S0);
104 
106  void end();
107 
113  void enableSensor();
114 
118  void disableSensor();
119 
126 
143  errorTypes readFromSensor(uint16_t command, uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high);
144 
156  errorTypes readMoreRegisters(uint16_t command, uint16_t data[], updTypes upd=UPD_low, safetyTypes safe=SAFE_high);
157 
167 
177 
185  errorTypes readActiveStatus(uint16_t &data);
186  errorTypes readIntMode1(uint16_t &data);
187  errorTypes readSIL(uint16_t &data);
188  errorTypes readIntMode2(uint16_t &data);
189  errorTypes readIntMode3(uint16_t &data);
190  errorTypes readOffsetX(uint16_t &data);
191  errorTypes readOffsetY(uint16_t &data);
192  errorTypes readSynch(uint16_t &data);
193  errorTypes readIFAB(uint16_t &data);
194  errorTypes readIntMode4(uint16_t &data);
195  errorTypes readTempCoeff(uint16_t &data);
196  errorTypes readTempDMag(uint16_t &data);
197  errorTypes readTempRaw(uint16_t &data);
198  errorTypes readTempIIFCnt(uint16_t &data);
199  errorTypes readTempT25(uint16_t &data);
200 
206  errorTypes readRawX(int16_t &data);
207 
213  errorTypes readRawY(int16_t &data);
214 
221  errorTypes getAngleRange(double &angleRange);
222 
229  errorTypes getAngleValue(double &angleValue);
238  errorTypes getAngleValue(double &angleValue, int16_t &rawAnglevalue, updTypes upd=UPD_low, safetyTypes safe=SAFE_high);
239 
251 
259  errorTypes getTemperature(double &temp);
268  errorTypes getTemperature(double &temp, int16_t &rawTemp, updTypes upd=UPD_low, safetyTypes safe=SAFE_high);
269 
277  errorTypes getAngleSpeed(double &angleSpeed);
286  errorTypes getAngleSpeed(double &angleSpeed,int16_t &rawSpeed, updTypes upd=UPD_low, safetyTypes safe=SAFE_high);
287 
293  errorTypes writeSlaveNumber(uint16_t dataToWrite);
294 
304  errorTypes writeToSensor(uint16_t command, uint16_t dataToWrite, bool changeCRC);
305 
311  errorTypes writeTempCoeffUpdate(uint16_t dataToWrite);
312 
318  errorTypes writeActivationStatus(uint16_t dataToWrite);
319  errorTypes writeIntMode1(uint16_t dataToWrite);
320  errorTypes writeSIL(uint16_t dataToWrite);
321  errorTypes writeIntMode2(uint16_t dataToWrite);
322  errorTypes writeIntMode3(uint16_t dataToWrite);
323  errorTypes writeOffsetX(uint16_t dataToWrite);
324  errorTypes writeOffsetY(uint16_t dataToWrite);
325  errorTypes writeSynch(uint16_t dataToWrite);
326  errorTypes writeIFAB(uint16_t dataToWrite);
327  errorTypes writeIntMode4(uint16_t dataToWrite);
328  errorTypes writeTempCoeff(uint16_t dataToWrite);
329 
331  uint16_t safetyWord;
332 
338 
346 
357 
366 
367  protected:
368 
369  uint16_t _command[2];
372 
381 
391  errorTypes checkSafety(uint16_t safety, uint16_t command, uint16_t* readreg, uint16_t length);
392 
400  void resetSafety();
401 
402 };
403 
408 #endif /* TLE5012B_HPP */
updTypes upd
Definition: E9000SPC.cpp:43
Definition: spic.hpp:21
Definition: gpio.hpp:21
Definition: TLE5012b.hpp:30
Definition: TLE5012b.hpp:52
errorTypes readRegMap()
Definition: TLE5012b.cpp:598
errorTypes readTempCoeff(uint16_t &data)
read register offset 0x0F
Definition: TLE5012b.cpp:366
errorTypes readTempT25(uint16_t &data)
read register offset 0x30
Definition: TLE5012b.cpp:382
errorTypes writeToSensor(uint16_t command, uint16_t dataToWrite, bool changeCRC)
Definition: TLE5012b.cpp:191
errorTypes writeActivationStatus(uint16_t dataToWrite)
write register offset 0x01
Definition: TLE5012b.cpp:580
errorTypes getAngleSpeed(double &angleSpeed)
Definition: TLE5012b.cpp:479
slaveNum
Definition: TLE5012b.hpp:40
errorTypes begin(uint8_t csPin, slaveNum slave=TLE5012B_S0)
begin method with default assignments for the SPI bus and the slave setting. Only the csPin is needed...
Reg reg
Register map.
Definition: TLE5012b.hpp:49
errorTypes readOffsetY(uint16_t &data)
read register offset 0x0B
Definition: TLE5012b.cpp:354
void enableSensor()
Definition: TLE5012b.cpp:136
errorTypes readOffsetX(uint16_t &data)
read register offset 0x0A
Definition: TLE5012b.cpp:350
void resetSafety()
Definition: TLE5012b.cpp:275
errorTypes readTempDMag(uint16_t &data)
read register offset 0x14
Definition: TLE5012b.cpp:370
GPIO * en
shield enable GPIO to switch sensor2go on/off
Definition: TLE5012b.hpp:48
errorTypes readBlockCRC()
Definition: TLE5012b.cpp:312
void disableSensor()
Definition: TLE5012b.cpp:143
errorTypes readIntMode2(uint16_t &data)
read register offset 0x08
Definition: TLE5012b.cpp:338
errorTypes readIntMode3(uint16_t &data)
read register offset 0x09
Definition: TLE5012b.cpp:342
errorTypes writeIntMode4(uint16_t dataToWrite)
write register offset 0x0E
Definition: TLE5012b.cpp:572
errorTypes writeOffsetX(uint16_t dataToWrite)
write register offset 0x0A
Definition: TLE5012b.cpp:556
errorTypes writeSIL(uint16_t dataToWrite)
write register offset 0x07
Definition: TLE5012b.cpp:588
uint16_t _registers[CRC_NUM_REGISTERS+1]
keeps track of the values stored in the 8 _registers, for which the CRC is calculated
Definition: TLE5012b.hpp:371
errorTypes writeSlaveNumber(uint16_t dataToWrite)
Definition: TLE5012b.cpp:592
uint16_t _command[2]
command write data [0] = command [1] = data to write
Definition: TLE5012b.hpp:369
safetyWord safetyStatus
Definition: TLE5012b.hpp:330
errorTypes writeTempCoeff(uint16_t dataToWrite)
write register offset 0x0F
Definition: TLE5012b.cpp:576
bool STAT_ANG
bits 12:12 Invalid angle value
Definition: TLE5012b.hpp:56
errorTypes readIntMode4(uint16_t &data)
read register offset 0x0E
Definition: TLE5012b.cpp:346
errorTypes writeSynch(uint16_t dataToWrite)
write register offset 0x0C
Definition: TLE5012b.cpp:564
errorTypes writeOffsetY(uint16_t dataToWrite)
write register offset 0x0B
Definition: TLE5012b.cpp:560
errorTypes writeIntMode3(uint16_t dataToWrite)
write register offset 0x09
Definition: TLE5012b.cpp:552
SPIC * sBus
SPI cover class as representation of the SPI bus.
Definition: TLE5012b.hpp:47
struct Tle5012b::safetyWord safetyWord_t
constructor for the Sensor
errorTypes checkSafety(uint16_t safety, uint16_t command, uint16_t *readreg, uint16_t length)
Definition: TLE5012b.cpp:229
errorTypes getAngleValue(double &angleValue)
Definition: TLE5012b.cpp:413
errorTypes readIFAB(uint16_t &data)
read register offset 0x0D
Definition: TLE5012b.cpp:362
errorTypes begin()
bool STAT_ERR
bits 14:14 System error
Definition: TLE5012b.hpp:54
uint16_t safetyWord
the last fetched safety word
Definition: TLE5012b.hpp:331
uint16_t _received[MAX_REGISTER_MEM]
fetched data from sensor with last word = safety word
Definition: TLE5012b.hpp:370
errorTypes getTemperature(double &temp)
Definition: TLE5012b.cpp:437
slaveNum mSlave
actual set slave number
Definition: TLE5012b.hpp:50
errorTypes readSIL(uint16_t &data)
read register offset 0x07
Definition: TLE5012b.cpp:330
errorTypes readFromSensor(uint16_t command, uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high)
Definition: TLE5012b.cpp:152
~Tle5012b()
default begin with standard pin setting
Definition: TLE5012b.cpp:123
errorTypes readTempIIFCnt(uint16_t &data)
read register offset 0x20
Definition: TLE5012b.cpp:374
bool STAT_ACC
bits 13:13 Interface access error
Definition: TLE5012b.hpp:55
errorTypes getNumRevolutions(int16_t &numRev, updTypes upd=UPD_low, safetyTypes safe=SAFE_high)
Definition: TLE5012b.cpp:461
errorTypes writeTempCoeffUpdate(uint16_t dataToWrite)
Definition: TLE5012b.cpp:207
Tle5012b()
destructor stops the Sensor
Definition: TLE5012b.cpp:115
slaveNum responseSlave()
Returns the safety word slave number to identify the sensor.
Definition: TLE5012b.hpp:64
errorTypes writeIntMode2(uint16_t dataToWrite)
write register offset 0x08
Definition: TLE5012b.cpp:548
void end()
Definition: TLE5012b.cpp:130
errorTypes readIntMode1(uint16_t &data)
read register offset 0x06
Definition: TLE5012b.cpp:334
errorTypes readActiveStatus(uint16_t &data)
read register offset 0x01
errorTypes readActivationStatus(uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high)
Definition: TLE5012b.cpp:326
errorTypes readSynch(uint16_t &data)
read register offset 0x0C
Definition: TLE5012b.cpp:358
errorTypes writeIFAB(uint16_t dataToWrite)
write register offset 0x0D
Definition: TLE5012b.cpp:568
errorTypes resetFirmware()
Definition: TLE5012b.cpp:283
errorTypes readRawY(int16_t &data)
Definition: TLE5012b.cpp:397
bool STAT_RES
<
Definition: TLE5012b.hpp:53
errorTypes writeIntMode1(uint16_t dataToWrite)
write register offset 0x06
Definition: TLE5012b.cpp:584
uint8_t CRC
bits 7:0 Status ADC Test
Definition: TLE5012b.hpp:58
uint16_t fetch_Safety(uint16_t reg)
Function separates safety word bits.
Definition: TLE5012b.hpp:76
errorTypes regularCrcUpdate()
Definition: TLE5012b.cpp:290
errorTypes writeInterfaceType(Reg::interfaceType_t iface)
Definition: TLE5012b.cpp:611
errorTypes getAngleRange(double &angleRange)
Definition: TLE5012b.cpp:529
errorTypes readStatus(uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high)
Definition: TLE5012b.cpp:322
errorTypes readMoreRegisters(uint16_t command, uint16_t data[], updTypes upd=UPD_low, safetyTypes safe=SAFE_high)
Definition: TLE5012b.cpp:171
errorTypes setCalibration(Reg::calibrationMode_t calMode)
Definition: TLE5012b.cpp:628
uint8_t RESP
bits 11:8 Sensor number response indicator
Definition: TLE5012b.hpp:57
errorTypes readRawX(int16_t &data)
Definition: TLE5012b.cpp:386
errorTypes readTempRaw(uint16_t &data)
read register offset 0x15
Definition: TLE5012b.cpp:378
@ TLE5012B_S3
TLE5012B_S3 fourth sensor and ditto.
Definition: TLE5012b.hpp:44
@ TLE5012B_S1
TLE5012B_S1 second sensor needs also a second CSQ.
Definition: TLE5012b.hpp:42
@ TLE5012B_S2
TLE5012B_S2 third sensor and ditto.
Definition: TLE5012b.hpp:43
@ TLE5012B_S0
TLE5012B_S0 default setting for only one sensor on the SPI.
Definition: TLE5012b.hpp:41
Definition: tle5012b_reg.hpp:35
calibrationMode_t
Automatic calibration of offset and amplitude synchronicity for applications with full-turn....
Definition: tle5012b_reg.hpp:46
interfaceType_t
List of possible interface types witch are preset by fuses and can be changed into each other.
Definition: tle5012b_reg.hpp:65
errorTypes
Error types from safety word.
Definition: tle5012b_util.hpp:73
#define MAX_REGISTER_MEM
max readable register values buffer
Definition: tle5012b_util.hpp:50
updTypes
Definition: tle5012b_util.hpp:84
#define CRC_NUM_REGISTERS
number of CRC relevant registers
Definition: tle5012b_util.hpp:49
safetyTypes
Definition: tle5012b_util.hpp:91
@ UPD_low
read normal registers
Definition: tle5012b_util.hpp:85
@ SAFE_high
switch on safety word generation
Definition: tle5012b_util.hpp:93
uint16_t command
read register beginning with REG_FSYNC
Definition: readMultipleRegisters.cpp:34