TLI4971 Current Sensor  1.1.1
C++ library of Infineons Magnetic Hall TLI4971 Current Sensor
TLI4971 Class Reference

#include <TLI4971.h>

Public Types

enum  OCDMODE { NONE, INTERRUPT, POLLING }
 
enum  MEASRANGE {
  FSR120 = 0x05, FSR100 = 0x06, FSR75 = 0x08, FSR50 = 0x0C,
  FSR37_5 = 0x10, FSR25 = 0x18
}
 
enum  OPMODE { SD_BID = 0, FD = 0x1<<5, SD_UNI = 0x2<<5, S_ENDED = 0x3<<5 }
 
enum  OCDDEGLITCH {
  D0, D1, D2, D3,
  D4, D5, D6, D7,
  D8, D9, D10, D11,
  D12, D13, D14, D15
}
 
enum  OCDTHR {
  THR1_1, THR1_2, THR1_3, THR1_4,
  THR1_5, THR1_6, THR1_7, THR1_8,
  THR2_1, THR2_2, THR2_3, THR2_4,
  THR2_5, THR2_6, THR2_7, THR2_8
}
 
enum  VRefExt {
  V1_65, V1_2, V1_5, V1_8,
  V2_5
}
 

Public Member Functions

 TLI4971 (int aout, int vref, int pwr, int sici, int ocd1, int ocd2, int mux, bool mc5V=true)
 Current sensor instance constructor. More...
 
 ~TLI4971 (void)
 Current sensor instance destructor . Reconfigurates pins to INPUT and ADC resolution to 8 Bit. More...
 
bool begin (void)
 Turn on sensor supply, initialy reads sensor configuration and checks if sensor can be configurated. More...
 
bool reset (void)
 Resets sensor to factory settings. More...
 
void end (void)
 Ends sensor library Turn off sensor supply. More...
 
double read (void)
 Reads sensor outputs and calculates current value. If Software OCD is used, this function can trigger the handler. More...
 
void ocdPolling (void)
 If polling is used as OCD mode this function will perform the polling. Needs to be called repeatedly, e.g. in loop. Handler functions for OCD-signals will be called by this method. SW-OCD will be detected as well, if in use. More...
 
void configAdc (bool logicLevel5V, int adcResolution=-1)
 Configurate ADC. More...
 
double getLastSwOcdCurrent (void)
 As soon as a Software OCD is triggered, the current value (> threshold) is stored. This function returns it. More...
 
bool registerOcd1Function (int mode, void(*func)(void))
 Register a handler, which shall be called when the sensor triggeres OCD1. More...
 
bool registerOcd2Function (int mode, void(*func)(void))
 Register a handler which shall be called when the sensor triggeres OCD2. More...
 
bool registerSwOcdFunction (double currentLevel, void(*func)(void))
 Register a handler, which shall be called when the sensor value exceeds a certain threshold. More...
 
bool setMeasRange (int measuringRange)
 Sets the measurement Range of the sensor (refer to Programming Guide). More...
 
bool setOpMode (int operatingMode)
 Set operating mode of the sensor (refer to Programming guide). More...
 
bool configOcd1 (bool enable, int threshold=THR1_1, int deglitchTime=D0)
 Configuration of OCD1. More...
 
bool configOcd2 (bool enable, int threshold=THR2_1, int deglitchTime=D0)
 Configuration of OCD2. More...
 
bool setOcdCompHyst (int threshold)
 Sets the OCD hysteresis. OCD signals will reset if current < 20% of the provided threshold. More...
 
bool setSwOcdCompHyst (double hysterese)
 Set Hysteresis value for SW-OCD. Signal will be reset when current < threshold - hysteresis. More...
 
bool setVrefExt (int vrefExtVoltage)
 Sets the reference voltage level. This can be used for Single Ended mode (setting needs to match external reference voltage), as well as Semi-differential Uni-directional mode (sensor will output this voltage at vRef). More...
 
bool setRatioGain (bool enable)
 If this is enabled the sensitivity is ratio-metric to VDD respective to VREF in single-ended mode. Default is disabled. More...
 
bool setRatioOff (bool enable)
 If this is enabled the ratio-metric offset behavior of the quiescent voltage is activated. Default is disabled. More...
 
bool getOcd1State (void)
 Reads state of ocd1-pin from sensor. More...
 
bool getOcd2State (void)
 Reads state of ocd2-pin from sensor. More...
 
bool getSwOcdState (void)
 Get state of Software OCD. More...
 

Member Enumeration Documentation

Enumerator
NONE 
INTERRUPT 
POLLING 
Enumerator
FSR120 
FSR100 
FSR75 
FSR50 
FSR37_5 
FSR25 
Enumerator
SD_BID 
FD 
SD_UNI 
S_ENDED 
Enumerator
D0 
D1 
D2 
D3 
D4 
D5 
D6 
D7 
D8 
D9 
D10 
D11 
D12 
D13 
D14 
D15 
Enumerator
THR1_1 
THR1_2 
THR1_3 
THR1_4 
THR1_5 
THR1_6 
THR1_7 
THR1_8 
THR2_1 
THR2_2 
THR2_3 
THR2_4 
THR2_5 
THR2_6 
THR2_7 
THR2_8 
Enumerator
V1_65 
V1_2 
V1_5 
V1_8 
V2_5 

Constructor & Destructor Documentation

TLI4971::TLI4971 ( int  aout,
int  vref,
int  pwr,
int  sici,
int  ocd1,
int  ocd2,
int  mux,
bool  mc5V = true 
)

Current sensor instance constructor.

Parameters
[in]aoutanalog channel for reading sensors analog output
[in]vrefanalog channel for sensors reference voltage output
[in]pwrpin for switching sensors VDD
[in]sicipin for SICI communication
[in]ocd1pin for over-current detection 1 signal of sensor
[in]ocd2pin for over-current detection 2 signal of sensor
[in]muxpin connected to analog mulitplexer on Shield2Go
[in]mc5Vstates whether microcontroller is a 5V or 3V3 device (needed for calculation)
Returns
void

Here is the call graph for this function:

TLI4971::~TLI4971 ( void  )

Current sensor instance destructor . Reconfigurates pins to INPUT and ADC resolution to 8 Bit.

Returns
void

Here is the call graph for this function:

Member Function Documentation

bool TLI4971::begin ( void  )

Turn on sensor supply, initialy reads sensor configuration and checks if sensor can be configurated.

Returns
bool
Return values
trueif sensor can be configurated
falseif sensor not available for configuration (SICI communication failed)

Here is the call graph for this function:

bool TLI4971::reset ( void  )

Resets sensor to factory settings.

Returns
bool
Return values
trueif restart succeded
falseif restart failed (SICI communication not possible)

Here is the call graph for this function:

void TLI4971::end ( void  )

Ends sensor library Turn off sensor supply.

Returns
void
double TLI4971::read ( void  )

Reads sensor outputs and calculates current value. If Software OCD is used, this function can trigger the handler.

Returns
double
Return values
currentvalue in Ampere
void TLI4971::ocdPolling ( void  )

If polling is used as OCD mode this function will perform the polling. Needs to be called repeatedly, e.g. in loop. Handler functions for OCD-signals will be called by this method. SW-OCD will be detected as well, if in use.

Returns
void

Here is the call graph for this function:

void TLI4971::configAdc ( bool  logicLevel5V,
int  adcResolution = -1 
)

Configurate ADC.

Parameters
[in]logicLevel5Vtrue for 5V microcontrollers, false for 3.3V microcontrollers
[in]adcResolutionnumber of Bits the ADC returns
Returns
void
double TLI4971::getLastSwOcdCurrent ( void  )

As soon as a Software OCD is triggered, the current value (> threshold) is stored. This function returns it.

Returns
double
Return values
lastcurrent value which triggered the Software-OCD
bool TLI4971::registerOcd1Function ( int  mode,
void(*)(void)  func 
)

Register a handler, which shall be called when the sensor triggeres OCD1.

Parameters
[in]modeINTERRUPT if hardware interrupt is available at the microcontroller for this pin. POLLING if no hardware interrupt is available for this pin. See as well ocdPolling() in this case.
[in]*funcpointer to handler function
Returns
bool
Return values
trueif registering was possible
falseif registering failed
bool TLI4971::registerOcd2Function ( int  mode,
void(*)(void)  func 
)

Register a handler which shall be called when the sensor triggeres OCD2.

Parameters
[in]modeINTERRUPT if hardware interrupt is available at the microcontroller for this pin. POLLING if no hardware interrupt is available for this pin. Use as well ocdPolling() in this case.
[in]*funcpointer to handler function
Returns
bool
Return values
trueif registering was possible
falseif registering failed
bool TLI4971::registerSwOcdFunction ( double  currentLevel,
void(*)(void)  func 
)

Register a handler, which shall be called when the sensor value exceeds a certain threshold.

Parameters
[in]currentLevelthreshold in Ampere
[in]*funcpointer to handler function
Returns
bool
Return values
trueif registering was possible
falseif registering failed
bool TLI4971::setMeasRange ( int  measuringRange)

Sets the measurement Range of the sensor (refer to Programming Guide).

Parameters
[in]measuringRangeRange of Current measurement. Possible values are: FSR120 = +/- 120A FSR100 = +/- 100A FSR75 = +/- 75A FSR50 = +/- 50A FSR37_5 = +/-37.5A FSR25 = +/- 25A
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::setOpMode ( int  operatingMode)

Set operating mode of the sensor (refer to Programming guide).

Parameters
[in]operatingModeMode of sensor operation. Changes the behaviour of AOut and Vref dependent of the measured current. Possible modes are: SD_BID = Semi-differential Bi-directional: Sensor provides reference voltage. Current flow in both directions are measured. FD = fully differential: vref is used as differential output signal from sensor. Increases resolution by factor 2. SD_UNI = Semi-differential Uni-directional: Sensor provides reference voltage. Direction of current flow is known by the application. See setVrefExt() as well. SE = Single Ended: Reference Voltage is provided by the µC or an external circuit. See setVrefExt() as well.
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::configOcd1 ( bool  enable,
int  threshold = THR1_1,
int  deglitchTime = D0 
)

Configuration of OCD1.

Parameters
[in]enabletrue to enable OCD1 signal, false to disable.
[in]thresholdset a Threshold level for OCD1. Range: [THR1_1 - THR1_8] according to Programming guide.
[in]deglitchTimeset a time for deglitching. Range: [D0 - D7] according to Programming guide.
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::configOcd2 ( bool  enable,
int  threshold = THR2_1,
int  deglitchTime = D0 
)

Configuration of OCD2.

Parameters
[in]enabletrue to enable OCD2 signal, false to disable.
[in]thresholdset a Threshold level for OCD2. Range: [THR2_1 - THR2_8] according to Programming guide.
[in]deglitchTimeset a time for deglitching. Range: [D0 - D15] according to Programming guide.
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::setOcdCompHyst ( int  threshold)

Sets the OCD hysteresis. OCD signals will reset if current < 20% of the provided threshold.

Parameters
[in]threshold20% of this Threshold are set as hysteresis for both OCD signals. Range: [THR1_1 - THR2_8]
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::setSwOcdCompHyst ( double  hysteresis)

Set Hysteresis value for SW-OCD. Signal will be reset when current < threshold - hysteresis.

Parameters
[in]hysteresisvalue in Ampere to be set as Hysteresis.
Returns
void
Return values
trueif setting hysteresis was successful
falseif setting hysteresis was not successful
bool TLI4971::setVrefExt ( int  vrefExtVoltage)

Sets the reference voltage level. This can be used for Single Ended mode (setting needs to match external reference voltage), as well as Semi-differential Uni-directional mode (sensor will output this voltage at vRef).

Parameters
[in]vrefExtVoltageVoltage level to set at vRef. Possible levels: V1_65 = 1.65V V1_2 = 1.2V V1_5 = 1.5V V1_8 = 1.8V V2_5 = 2.5V
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::setRatioGain ( bool  enable)

If this is enabled the sensitivity is ratio-metric to VDD respective to VREF in single-ended mode. Default is disabled.

Parameters
[in]enabletrue: ratio-metric gain is enabled false: ratio-metric gain is disabled
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed
bool TLI4971::setRatioOff ( bool  enable)

If this is enabled the ratio-metric offset behavior of the quiescent voltage is activated. Default is disabled.

Parameters
[in]enabletrue: ratio-metric offset is enabled false: ratio-metric offset is disabled
Returns
bool
Return values
trueif configuration succeeded
falseif configuration failed

Here is the call graph for this function:

bool TLI4971::getOcd1State ( void  )

Reads state of ocd1-pin from sensor.

Returns
bool
Return values
trueif OCD1 is triggered
falseif OCD1 is not triggered
bool TLI4971::getOcd2State ( void  )

Reads state of ocd2-pin from sensor.

Returns
bool
Return values
trueif OCD2 is triggered
falseif OCD2 is not triggered
bool TLI4971::getSwOcdState ( void  )

Get state of Software OCD.

Returns
bool
Return values
trueif Software-OCD is triggered
falseif Software-OCD is not triggered

The documentation for this class was generated from the following files: