Data Structures | |
class | Tle5012b |
struct | Tle5012b::safetyWord |
Enumerations | |
enum | Tle5012b::slaveNum { Tle5012b::TLE5012B_S0 = 0x0000 , Tle5012b::TLE5012B_S1 = 0x2000 , Tle5012b::TLE5012B_S2 = 0x4000 , Tle5012b::TLE5012B_S3 = 0x6000 } |
Functions | |
slaveNum | Tle5012b::safetyWord::responseSlave () |
Returns the safety word slave number to identify the sensor. More... | |
uint16_t | Tle5012b::safetyWord::fetch_Safety (uint16_t reg) |
Function separates safety word bits. More... | |
errorTypes | Tle5012b::begin () |
errorTypes | Tle5012b::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. More... | |
errorTypes | Tle5012b::readActiveStatus (uint16_t &data) |
read register offset 0x01 More... | |
Variables | |
SPIC * | Tle5012b::sBus |
SPI cover class as representation of the SPI bus. More... | |
GPIO * | Tle5012b::en |
shield enable GPIO to switch sensor2go on/off More... | |
Reg | Tle5012b::reg |
Register map. More... | |
slaveNum | Tle5012b::mSlave |
actual set slave number More... | |
bool | Tle5012b::safetyWord::STAT_RES |
< More... | |
bool | Tle5012b::safetyWord::STAT_ERR |
bits 14:14 System error More... | |
bool | Tle5012b::safetyWord::STAT_ACC |
bits 13:13 Interface access error More... | |
bool | Tle5012b::safetyWord::STAT_ANG |
bits 12:12 Invalid angle value More... | |
uint8_t | Tle5012b::safetyWord::RESP |
bits 11:8 Sensor number response indicator More... | |
uint8_t | Tle5012b::safetyWord::CRC |
bits 7:0 Status ADC Test More... | |
struct Tle5012b::safetyWord | Tle5012b::safetyWord_t |
constructor for the Sensor More... | |
safetyWord | Tle5012b::safetyStatus |
uint16_t | Tle5012b::safetyWord |
the last fetched safety word More... | |
uint16_t | Tle5012b::_command [2] |
command write data [0] = command [1] = data to write More... | |
uint16_t | Tle5012b::_received [MAX_REGISTER_MEM] |
fetched data from sensor with last word = safety word More... | |
uint16_t | Tle5012b::_registers [CRC_NUM_REGISTERS+1] |
keeps track of the values stored in the 8 _registers, for which the CRC is calculated More... | |
class Tle5012b |
Public Types | |
enum | slaveNum { TLE5012B_S0 = 0x0000 , TLE5012B_S1 = 0x2000 , TLE5012B_S2 = 0x4000 , TLE5012B_S3 = 0x6000 } |
Public Member Functions | |
errorTypes | begin () |
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. More... | |
errorTypes | readActiveStatus (uint16_t &data) |
read register offset 0x01 More... | |
Data Fields | |
SPIC * | sBus |
SPI cover class as representation of the SPI bus. More... | |
GPIO * | en |
shield enable GPIO to switch sensor2go on/off More... | |
Reg | reg |
Register map. More... | |
slaveNum | mSlave |
actual set slave number More... | |
struct Tle5012b::safetyWord | safetyWord_t |
constructor for the Sensor More... | |
safetyWord | safetyStatus |
uint16_t | safetyWord |
the last fetched safety word More... | |
Protected Attributes | |
uint16_t | _command [2] |
command write data [0] = command [1] = data to write More... | |
uint16_t | _received [MAX_REGISTER_MEM] |
fetched data from sensor with last word = safety word More... | |
uint16_t | _registers [CRC_NUM_REGISTERS+1] |
keeps track of the values stored in the 8 _registers, for which the CRC is calculated More... | |
TLE5012b.cpp - core library for the TLE5012B angle sensor. | |
GMR-based angle sensor for angular position sensing in automotive applications Core Library
SPDX-License-Identifier: MIT | |
Tle5012b () | |
destructor stops the Sensor More... | |
~Tle5012b () | |
default begin with standard pin setting More... | |
void | end () |
void | enableSensor () |
void | disableSensor () |
errorTypes | readBlockCRC () |
errorTypes | readFromSensor (uint16_t command, uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | readMoreRegisters (uint16_t command, uint16_t data[], updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | readStatus (uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | readActivationStatus (uint16_t &data, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | readIntMode1 (uint16_t &data) |
read register offset 0x06 More... | |
errorTypes | readSIL (uint16_t &data) |
read register offset 0x07 More... | |
errorTypes | readIntMode2 (uint16_t &data) |
read register offset 0x08 More... | |
errorTypes | readIntMode3 (uint16_t &data) |
read register offset 0x09 More... | |
errorTypes | readOffsetX (uint16_t &data) |
read register offset 0x0A More... | |
errorTypes | readOffsetY (uint16_t &data) |
read register offset 0x0B More... | |
errorTypes | readSynch (uint16_t &data) |
read register offset 0x0C More... | |
errorTypes | readIFAB (uint16_t &data) |
read register offset 0x0D More... | |
errorTypes | readIntMode4 (uint16_t &data) |
read register offset 0x0E More... | |
errorTypes | readTempCoeff (uint16_t &data) |
read register offset 0x0F More... | |
errorTypes | readTempDMag (uint16_t &data) |
read register offset 0x14 More... | |
errorTypes | readTempRaw (uint16_t &data) |
read register offset 0x15 More... | |
errorTypes | readTempIIFCnt (uint16_t &data) |
read register offset 0x20 More... | |
errorTypes | readTempT25 (uint16_t &data) |
read register offset 0x30 More... | |
errorTypes | readRawX (int16_t &data) |
errorTypes | readRawY (int16_t &data) |
errorTypes | getAngleRange (double &angleRange) |
errorTypes | getAngleValue (double &angleValue) |
errorTypes | getAngleValue (double &angleValue, int16_t &rawAnglevalue, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | getNumRevolutions (int16_t &numRev, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | getTemperature (double &temp) |
errorTypes | getTemperature (double &temp, int16_t &rawTemp, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | getAngleSpeed (double &angleSpeed) |
errorTypes | getAngleSpeed (double &angleSpeed, int16_t &rawSpeed, updTypes upd=UPD_low, safetyTypes safe=SAFE_high) |
errorTypes | writeSlaveNumber (uint16_t dataToWrite) |
errorTypes | writeToSensor (uint16_t command, uint16_t dataToWrite, bool changeCRC) |
errorTypes | writeTempCoeffUpdate (uint16_t dataToWrite) |
errorTypes | writeActivationStatus (uint16_t dataToWrite) |
write register offset 0x01 More... | |
errorTypes | writeIntMode1 (uint16_t dataToWrite) |
write register offset 0x06 More... | |
errorTypes | writeSIL (uint16_t dataToWrite) |
write register offset 0x07 More... | |
errorTypes | writeIntMode2 (uint16_t dataToWrite) |
write register offset 0x08 More... | |
errorTypes | writeIntMode3 (uint16_t dataToWrite) |
write register offset 0x09 More... | |
errorTypes | writeOffsetX (uint16_t dataToWrite) |
write register offset 0x0A More... | |
errorTypes | writeOffsetY (uint16_t dataToWrite) |
write register offset 0x0B More... | |
errorTypes | writeSynch (uint16_t dataToWrite) |
write register offset 0x0C More... | |
errorTypes | writeIFAB (uint16_t dataToWrite) |
write register offset 0x0D More... | |
errorTypes | writeIntMode4 (uint16_t dataToWrite) |
write register offset 0x0E More... | |
errorTypes | writeTempCoeff (uint16_t dataToWrite) |
write register offset 0x0F More... | |
errorTypes | resetFirmware () |
errorTypes | readRegMap () |
errorTypes | writeInterfaceType (Reg::interfaceType_t iface) |
errorTypes | setCalibration (Reg::calibrationMode_t calMode) |
errorTypes | regularCrcUpdate () |
errorTypes | checkSafety (uint16_t safety, uint16_t command, uint16_t *readreg, uint16_t length) |
void | resetSafety () |
struct Tle5012b::safetyWord |
Public Member Functions | |
slaveNum | responseSlave () |
Returns the safety word slave number to identify the sensor. More... | |
uint16_t | fetch_Safety (uint16_t reg) |
Function separates safety word bits. More... | |
Data Fields | |
bool | STAT_RES |
< More... | |
bool | STAT_ERR |
bits 14:14 System error More... | |
bool | STAT_ACC |
bits 13:13 Interface access error More... | |
bool | STAT_ANG |
bits 12:12 Invalid angle value More... | |
uint8_t | RESP |
bits 11:8 Sensor number response indicator More... | |
uint8_t | CRC |
bits 7:0 Status ADC Test More... | |
enum Tle5012b::slaveNum |
Offset for the slave number register to identify the right selected slave. Max 4 slaves with separated CSQ lines are possible. If more than one sensor is used on the SPI interface, than the SNR register must we written with the correct slave number
|
inline |
Returns the safety word slave number to identify the sensor.
|
inline |
Function separates safety word bits.
[in,out] | reg | actual safety or last fetched as default |
Tle5012b::Tle5012b | ( | ) |
destructor stops the Sensor
Tle5012b::~Tle5012b | ( | ) |
default begin with standard pin setting
errorTypes Tle5012b::begin | ( | ) |
errorTypes Tle5012b::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.
csPin | pin number of the CS pin |
slave | slave offset setting for the SNR register, default is TLE5012B_S0 |
Ends the comunication and switches the sensor off, if possible (only Sensor2go kit)
void Tle5012b::end | ( | void | ) |
void Tle5012b::enableSensor | ( | ) |
Function enables Sensor by switch on EN pin which is only possible on Sensor2go shields, but also sets chipselect high. So it is called always.
void Tle5012b::disableSensor | ( | ) |
Functions disables Sensor by switch off EN pin (only possible on Sensor2go shield)
errorTypes Tle5012b::readBlockCRC | ( | ) |
Reads the block of _registers from addresses 08 - 0F in order to figure out the CRC. ATTENTION: You need a memory chunk of unit16_t * CRC Registers + 1 * uint16_t for the safety word.
errorTypes Tle5012b::readFromSensor | ( | uint16_t | command, |
uint16_t & | data, | ||
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
General read function for reading _registers from the Tle5012b.
structure of command word, the numbers represent the bit position of the 2 byte command 15 - 0 write, 1 read 14:11 - 0000 for default operational access for addresses between 0x00 - 0x04, 1010 for configuration access for addresses between 0x05 - 0x11 10 - 0 access to current value, 1 access to value in update buffer 9:4 - access to 6 bit register address 3:0 - 4 bit number of data words.
[in] | command | the command for reading |
[out] | data | where the data received from the _registers will be stored |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or not (SAFE_low) |
errorTypes Tle5012b::readMoreRegisters | ( | uint16_t | command, |
uint16_t | data[], | ||
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
Can be used to read 1 or more consecutive _registers, and the values used to read 1 or more than 1 consecutive _registers. The maximum amount of registers are limited by the bit 3-0 of the command word, which means you can read max 15 registers and one safety word at once.
[in] | command | the command for reading |
[out] | data | where the data received from the _registers will be stored |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::readStatus | ( | uint16_t & | data, |
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
This functions reads the main status word for the sensor, mainly for checking with the additional safety word
[out] | data | pointer with the received data word |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::readActivationStatus | ( | uint16_t & | data, |
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
This functions reads activation status word for the sensor, which held on/off information for all optional checks and additional functions
[out] | data | pointer with the received data word |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::readActiveStatus | ( | uint16_t & | data | ) |
read register offset 0x01
The next functions are used primarily for storing the parameters and control of how the sensor works. The values stored in them are used to calculate the CRC, and their values are stored in the private component of the class, _registers.
[out] | data | where the data received from the _registers will be stored |
errorTypes Tle5012b::readIntMode1 | ( | uint16_t & | data | ) |
read register offset 0x06
errorTypes Tle5012b::readSIL | ( | uint16_t & | data | ) |
read register offset 0x07
errorTypes Tle5012b::readIntMode2 | ( | uint16_t & | data | ) |
read register offset 0x08
errorTypes Tle5012b::readIntMode3 | ( | uint16_t & | data | ) |
read register offset 0x09
errorTypes Tle5012b::readOffsetX | ( | uint16_t & | data | ) |
read register offset 0x0A
errorTypes Tle5012b::readOffsetY | ( | uint16_t & | data | ) |
read register offset 0x0B
errorTypes Tle5012b::readSynch | ( | uint16_t & | data | ) |
read register offset 0x0C
errorTypes Tle5012b::readIFAB | ( | uint16_t & | data | ) |
read register offset 0x0D
errorTypes Tle5012b::readIntMode4 | ( | uint16_t & | data | ) |
read register offset 0x0E
errorTypes Tle5012b::readTempCoeff | ( | uint16_t & | data | ) |
read register offset 0x0F
errorTypes Tle5012b::readTempDMag | ( | uint16_t & | data | ) |
read register offset 0x14
errorTypes Tle5012b::readTempRaw | ( | uint16_t & | data | ) |
read register offset 0x15
errorTypes Tle5012b::readTempIIFCnt | ( | uint16_t & | data | ) |
read register offset 0x20
errorTypes Tle5012b::readTempT25 | ( | uint16_t & | data | ) |
read register offset 0x30
errorTypes Tle5012b::readRawX | ( | int16_t & | data | ) |
The rawX value is signed 16 bit value
data | pointer to 16bit word |
errorTypes Tle5012b::readRawY | ( | int16_t & | data | ) |
The rawY value is signed 16 bit value
data | pointer to 16bit word |
errorTypes Tle5012b::getAngleRange | ( | double & | angleRange | ) |
Returns the Angle Range Angle Range is stored in bytes 14 - 4 of MOD_2.
angleRange | pointer to 16bit double value |
errorTypes Tle5012b::getAngleValue | ( | double & | angleValue | ) |
Returns the angleValue calculated on the base of a 15 bit signed integer. However, the register returns 16 bits, so we need to do some bit arithmetic.
[in,out] | angleValue | pointer to 16bit double angle value |
errorTypes Tle5012b::getAngleValue | ( | double & | angleValue, |
int16_t & | rawAnglevalue, | ||
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
Same function as before but also returns a pointer to the raw data
[in,out] | angleValue | pointer to 16bit double angle value |
[in,out] | rawAnglevalue | point to an int16_t raw data value |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::getNumRevolutions | ( | int16_t & | numRev, |
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
Returns the number of revolutions done from the angle value which is a 9 bit signed integer. However, the register returns 16 bits, so we need to do some bit arithmetic. Therefore the resulting revolution can b only between -256 < numRev < 256 and it will switch from positive to negative and vice versa values at the borders.
[in,out] | numRev | pointer to 16bit word for the number of revolutions |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::getTemperature | ( | double & | temp | ) |
Return the temperature. The temperature value is a 9 bit signed integer. However, the register returns 16 bits, so we need to do some bit arithmetic.
[in,out] | temp | pointer to 16bit double value of the temperature |
errorTypes Tle5012b::getTemperature | ( | double & | temp, |
int16_t & | rawTemp, | ||
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
Same as above but also returns a pointer to the raw data
[in,out] | temp | pointer to 16bit double value of the temperature |
[in,out] | rawTemp | pointer to int16_t raw value data |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::getAngleSpeed | ( | double & | angleSpeed | ) |
Returns the calculated angle speed. The angle speed is a 15 bit signed integer, however, the register returns 16 bits, so we need to do some bit arithmetic.
[in,out] | angleSpeed | pointer to 16bit double value |
errorTypes Tle5012b::getAngleSpeed | ( | double & | angleSpeed, |
int16_t & | rawSpeed, | ||
updTypes | upd = UPD_low , |
||
safetyTypes | safe = SAFE_high |
||
) |
Same as above but also returns a pointer to the raw data
[in,out] | angleSpeed | angleSpeed pointer to 16bit double value |
[in,out] | rawSpeed | pointer to int16_t raw value data |
[in] | upd | read from update (UPD_high) register or directly (default, UPD_low) |
[in] | safe | generate safety word (default, SAFE_high) or no (SAFE_low) |
errorTypes Tle5012b::writeSlaveNumber | ( | uint16_t | dataToWrite | ) |
Function sets the SNR register with the correct slave number
[in] | dataToWrite | the new data that will be written to the register |
errorTypes Tle5012b::writeToSensor | ( | uint16_t | command, |
uint16_t | dataToWrite, | ||
bool | changeCRC | ||
) |
General write function for writing registers to the Tle5012b. The safety flag will be set always and only some of all registers are writable. See documentation for further information.
[in] | command | the command to execute the write |
[in] | dataToWrite | the new data that will be written to the register |
[in] | changeCRC | the registerIndex helps figure out in which register the value changed, so that we don't need to read all the register again to calculate the CRC |
errorTypes Tle5012b::writeTempCoeffUpdate | ( | uint16_t | dataToWrite | ) |
This function is used in order to update the CRC in the register 0F(second byte)
[in] | dataToWrite | the new data that will be written to the register |
errorTypes Tle5012b::writeActivationStatus | ( | uint16_t | dataToWrite | ) |
write register offset 0x01
Standard function used for updating the CRC
[in] | dataToWrite | the new data that will be written to the register |
errorTypes Tle5012b::writeIntMode1 | ( | uint16_t | dataToWrite | ) |
write register offset 0x06
errorTypes Tle5012b::writeSIL | ( | uint16_t | dataToWrite | ) |
write register offset 0x07
errorTypes Tle5012b::writeIntMode2 | ( | uint16_t | dataToWrite | ) |
write register offset 0x08
errorTypes Tle5012b::writeIntMode3 | ( | uint16_t | dataToWrite | ) |
write register offset 0x09
errorTypes Tle5012b::writeOffsetX | ( | uint16_t | dataToWrite | ) |
write register offset 0x0A
errorTypes Tle5012b::writeOffsetY | ( | uint16_t | dataToWrite | ) |
write register offset 0x0B
errorTypes Tle5012b::writeSynch | ( | uint16_t | dataToWrite | ) |
write register offset 0x0C
errorTypes Tle5012b::writeIFAB | ( | uint16_t | dataToWrite | ) |
write register offset 0x0D
errorTypes Tle5012b::writeIntMode4 | ( | uint16_t | dataToWrite | ) |
write register offset 0x0E
errorTypes Tle5012b::writeTempCoeff | ( | uint16_t | dataToWrite | ) |
write register offset 0x0F
errorTypes Tle5012b::resetFirmware | ( | ) |
Function reset the Sensor to fuse defaults
errorTypes Tle5012b::readRegMap | ( | ) |
Function reads all readable sensor registers and separates the information fields. This function is needed for finding the selected interface type.
errorTypes Tle5012b::writeInterfaceType | ( | Reg::interfaceType_t | iface | ) |
Functions switches between all possible interface types. ATTENTION: The different interfaces support not always all values, see documentation for the ability of each interface. If you want to be save, than choose the default SSC interface which always supports all possible parameter.
iface | type of interface to switch to |
errorTypes Tle5012b::setCalibration | ( | Reg::calibrationMode_t | calMode | ) |
Function set the sensors calibration mode. Keep in mind, not all Sensor interface setups have the autocalibration switched on, so maybe you have to set it explicitly.
[in] | calMode | the auto calibration mode to set |
|
protected |
This function is called each time any register in the range 08 - 0F(first byte) is changed. It calculates the new CRC based on the value of all the _registers and then stores the value in 0F(second byte)
|
protected |
checks the safety by looking at the safety word and calculating the CRC such that the data received is valid
safety | register with the CRC check data |
command | the command to execute the write |
readreg | pointer to the read data |
length | the length of the data structure |
|
protected |
When an error occurs in the safety word, the error bit remains 0(error), until the status register is read again. Flushes out safety errors, that might have occurred by reading the register without a safety word. In case the safety word sends an error, this function is called so that the error bit is reset to 1.
SPIC* Tle5012b::sBus |
SPI cover class as representation of the SPI bus.
Reg Tle5012b::reg |
Register map.
slaveNum Tle5012b::mSlave |
actual set slave number
bool Tle5012b::safetyWord::STAT_RES |
<
Safety word bit setting
bits 15:15 Indication of chip reset or watchdog overflow
bool Tle5012b::safetyWord::STAT_ERR |
bits 14:14 System error
bool Tle5012b::safetyWord::STAT_ACC |
bits 13:13 Interface access error
bool Tle5012b::safetyWord::STAT_ANG |
bits 12:12 Invalid angle value
uint8_t Tle5012b::safetyWord::RESP |
bits 11:8 Sensor number response indicator
uint8_t Tle5012b::safetyWord::CRC |
bits 7:0 Status ADC Test
struct Tle5012b::safetyWord Tle5012b::safetyWord_t |
constructor for the Sensor
safetyWord Tle5012b::safetyStatus |
uint16_t Tle5012b::safetyWord |
the last fetched safety word
|
protected |
command write data [0] = command [1] = data to write
|
protected |
fetched data from sensor with last word = safety word
|
protected |
keeps track of the values stored in the 8 _registers, for which the CRC is calculated