Class Tle5012b
Defined in File TLE5012b.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Derived Types
public tle5012::Tle5012Ino(Class Tle5012Ino)public tle5012::Tle5012Wiced(Class Tle5012Wiced)
Class Documentation
-
class Tle5012b
Subclassed by tle5012::Tle5012Ino, tle5012::Tle5012Wiced
TLE5012b.cpp - core library for the TLx5012B angle sensor family.
GMR-based angle sensor for angular position sensing in automotive applications
SPDX-License-Identifier: MIT
- Author
Infineon Technologies AG
- Copyright
2019-2024 Infineon Technologies AG
- Version
4.0.0
-
Tle5012b()
destructor stops the Sensor
-
~Tle5012b()
default begin with standard pin setting
-
void end()
-
void enableSensor()
Function enables Sensor by switch on EN pin which is only possible on Sensor2go shields, but also sets chip select high. So it is called always.
-
void disableSensor()
Functions disables Sensor by switch off EN pin (only possible on Sensor2go shield)
-
errorTypes 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.
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
command – [in] the command for reading
data – [out] where the data received from the _registers will be stored
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or not (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
command – [in] the command for reading
data – [out] where the data received from the _registers will be stored
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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
- Parameters:
data – [out] pointer with the received data word
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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
- Parameters:
data – [out] pointer with the received data word
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes readIntMode1(uint16_t &data)
read register offset 0x06
-
errorTypes readSIL(uint16_t &data)
read register offset 0x07
-
errorTypes readIntMode2(uint16_t &data)
read register offset 0x08
-
errorTypes readIntMode3(uint16_t &data)
read register offset 0x09
-
errorTypes readOffsetX(uint16_t &data)
read register offset 0x0A
-
errorTypes readOffsetY(uint16_t &data)
read register offset 0x0B
-
errorTypes readSynch(uint16_t &data)
read register offset 0x0C
-
errorTypes readIFAB(uint16_t &data)
read register offset 0x0D
-
errorTypes readIntMode4(uint16_t &data)
read register offset 0x0E
-
errorTypes readTempCoeff(uint16_t &data)
read register offset 0x0F
-
errorTypes readTempDMag(uint16_t &data)
read register offset 0x14
-
errorTypes readTempRaw(uint16_t &data)
read register offset 0x15
-
errorTypes readTempIIFCnt(uint16_t &data)
read register offset 0x20
-
errorTypes readTempT25(uint16_t &data)
read register offset 0x30
-
errorTypes readRawX(int16_t &data)
The rawX value is signed 16 bit value
- Parameters:
data – pointer to 16bit word
- Returns:
CRC error type
-
errorTypes readRawY(int16_t &data)
The rawY value is signed 16 bit value
- Parameters:
data – pointer to 16bit word
- Returns:
CRC error type
-
errorTypes getAngleRange(double &angleRange)
Returns the Angle Range Angle Range is stored in bytes 14 - 4 of MOD_2.
- Parameters:
angleRange – pointer to 16bit double value
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
angleValue – [inout] pointer to 16bit double angle value
- Returns:
CRC error type
-
errorTypes 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
- Parameters:
angleValue – [inout] pointer to 16bit double angle value
rawAngleValue – [inout] point to an int16_t raw data value
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
numRev – [inout] pointer to 16bit word for the number of revolutions
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
temp – [inout] pointer to 16bit double value of the temperature
- Returns:
CRC error type
-
errorTypes 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
- Parameters:
temp – [inout] pointer to 16bit double value of the temperature
rawTemp – [inout] pointer to int16_t raw value data
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
angleSpeed – [inout] pointer to 16bit double value
- Returns:
CRC error type
-
errorTypes 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
- Parameters:
angleSpeed – [inout] angleSpeed pointer to 16bit double value
rawSpeed – [inout] pointer to int16_t raw value data
upd – [in] read from update (UPD_high) register or directly (default, UPD_low)
safe – [in] generate safety word (default, SAFE_high) or no (SAFE_low)
- Returns:
CRC error type
-
errorTypes writeSlaveNumber(uint16_t dataToWrite)
Function sets the SNR register with the correct slave number
- Parameters:
dataToWrite – [in] the new data that will be written to the register
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
command – [in] the command to execute the write
dataToWrite – [in] the new data that will be written to the register
changeCRC – [in] 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
- Returns:
CRC error type
-
errorTypes writeTempCoeffUpdate(uint16_t dataToWrite)
This function is used in order to update the CRC in the register 0F(second byte)
- Parameters:
dataToWrite – [in] the new data that will be written to the register
- Returns:
CRC error type
-
errorTypes writeActivationStatus(uint16_t dataToWrite)
write register offset 0x01
Standard function used for updating the CRC
- Parameters:
dataToWrite – [in] the new data that will be written to the register
- Returns:
CRC error type
-
errorTypes writeIntMode1(uint16_t dataToWrite)
write register offset 0x06
-
errorTypes writeSIL(uint16_t dataToWrite)
write register offset 0x07
-
errorTypes writeIntMode2(uint16_t dataToWrite)
write register offset 0x08
-
errorTypes writeIntMode3(uint16_t dataToWrite)
write register offset 0x09
-
errorTypes writeOffsetX(uint16_t dataToWrite)
write register offset 0x0A
-
errorTypes writeOffsetY(uint16_t dataToWrite)
write register offset 0x0B
-
errorTypes writeSynch(uint16_t dataToWrite)
write register offset 0x0C
-
errorTypes writeIFAB(uint16_t dataToWrite)
write register offset 0x0D
-
errorTypes writeIntMode4(uint16_t dataToWrite)
write register offset 0x0E
-
errorTypes writeTempCoeff(uint16_t dataToWrite)
write register offset 0x0F
-
errorTypes resetFirmware()
Function reset the Sensor to fuse defaults
- Returns:
CRC error type
-
errorTypes readRegMap()
Function reads all readable sensor registers and separates the information fields. This function is needed for finding the selected interface type.
- Returns:
CRC error type
-
errorTypes 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.
- Parameters:
iface – type of interface to switch to
- Returns:
CRC error type
-
errorTypes setCalibration(Reg::calibrationMode_t calMode)
Function set the sensors calibration mode. Keep in mind, not all Sensor interface setups have the auto calibration switched on, so maybe you have to set it explicitly.
- Parameters:
calMode – [in] the auto calibration mode to set
- Returns:
CRC error type
-
errorTypes regularCrcUpdate()
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)
- Returns:
CRC error type
-
errorTypes checkSafety(uint16_t safety, uint16_t command, uint16_t *readreg, uint16_t length)
checks the safety by looking at the safety word and calculating the CRC such that the data received is valid
- Parameters:
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
- Returns:
CRC error type
-
void resetSafety()
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.
Public Types
-
enum 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
Values:
-
enumerator TLE5012B_S0
TLE5012B_S0 default setting for only one sensor on the SPI.
-
enumerator TLE5012B_S1
TLE5012B_S1 second sensor needs also a second CS pin.
-
enumerator TLE5012B_S2
TLE5012B_S2 third sensor and ditto.
-
enumerator TLE5012B_S3
TLE5012B_S3 fourth sensor and ditto.
-
enumerator TLE5012B_S0
Public 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.
Ends the communication and switches the sensor off, if possible (only Sensor2go kit)
- Parameters:
csPin – pin number of the CS pin
slave – slave offset setting for the SNR register, default is TLE5012B_S0
-
errorTypes 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.
- Parameters:
data – [out] where the data received from the _registers will be stored
- Returns:
CRC error type
Public Members
-
SPICPAL *sBus
SPI cover class as representation of the SPI bus.
-
GPIOPAL *en
shield enable GPIOPal to switch sensor2go on/off
-
Reg reg
Register map.
-
slaveNum mSlave
actual set slave number
-
struct tle5012::Tle5012b::safetyWord safetyWord_t
constructor for the Sensor
-
safetyWord safetyStatus
-
uint16_t safetyWord
the last fetched safety word
Protected Attributes
-
uint16_t _command[2]
command write data [0] = command [1] = data to write
-
uint16_t _received[0x0030]
fetched data from sensor with last word = safety word
-
uint16_t _registers[0x0008 + 1]
keeps track of the values stored in the 8 _registers, for which the CRC is calculated
-
struct safetyWord
Public Functions
-
inline slaveNum responseSlave()
Returns the safety word slave number to identify the sensor.
- Returns:
slaveNum setting in safety word
-
inline uint16_t fetch_Safety(uint16_t reg)
Function separates safety word bits.
- Parameters:
reg – [inout] actual safety or last fetched as default
- Returns:
safety word
Public Members
-
bool STAT_RES
<
Safety word bit setting
bits 15:15 Indication of chip reset or watchdog overflow
-
bool STAT_ERR
bits 14:14 System error
-
bool STAT_ACC
bits 13:13 Interface access error
-
bool STAT_ANG
bits 12:12 Invalid angle value
-
uint8_t RESP
bits 11:8 Sensor number response indicator
-
uint8_t CRC
bits 7:0 Status ADC Test
-
inline slaveNum responseSlave()