TLI4971 Current Sensor  1.1.1
C++ library of Infineons Magnetic Hall TLI4971 Current Sensor
TLI4971.h
Go to the documentation of this file.
1 
8 #ifndef TLI4971_H_INCLUDED
9 #define TLI4971_H_INCLUDED
10 
11 #include <Arduino.h>
12 #include <stdlib.h>
13 #include <stdbool.h>
14 #include "util/SICI.h"
15 
16 
20 class TLI4971
21 {
22  public:
23 
25 
26  enum MEASRANGE { FSR120 = 0x05, FSR100 = 0x06, FSR75 = 0x08, FSR50 = 0x0C, FSR37_5 = 0x10, FSR25 = 0x18 };
27  enum OPMODE { SD_BID = 0, FD = 0x1<<5 , SD_UNI = 0x2<<5, S_ENDED = 0x3<<5 };
28  enum OCDDEGLITCH { D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15 };
30  enum VRefExt { V1_65, V1_2, V1_5, V1_8, V2_5 };
31 
32  TLI4971(int aout, int vref, int pwr, int sici, int ocd1, int ocd2, int mux, bool mc5V = true);
33  ~TLI4971(void);
34  bool begin(void);
35  bool reset(void);
36  void end(void);
37  double read(void);
38  void ocdPolling(void);
39 
40  void configAdc(bool logicLevel5V, int adcResolution = -1);
41 
42  double getLastSwOcdCurrent(void);
43 
44  bool registerOcd1Function(int mode, void (*func)(void));
45  bool registerOcd2Function(int mode, void (*func)(void));
46  bool registerSwOcdFunction(double currentLevel, void (*func)(void));
47 
48  bool setMeasRange(int measuringRange);
49  bool setOpMode(int operatingMode);
50  bool configOcd1(bool enable, int threshold = THR1_1, int deglitchTime = D0);
51  bool configOcd2(bool enable, int threshold = THR2_1, int deglitchTime = D0);
52  bool setOcdCompHyst(int threshold);
53  bool setSwOcdCompHyst(double hysterese);
54  bool setVrefExt(int vrefExtVoltage);
55  bool setRatioGain(bool enable);
56  bool setRatioOff(bool enable);
57 
58  bool getOcd1State(void);
59  bool getOcd2State(void);
60  bool getSwOcdState(void);
61 
62 
63 
64  private:
65  //const Sici_TLI4971::_SICI_timing SICI_timing = {150,400,60,120,120,60,16,120,35,20,20};
66  tli4971::Sici bus = tli4971::Sici(0,0);
67  int ocd1Pin;
68  int ocd2Pin;
69  int pwrPin;
70  int vrefPin;
71  int aoutPin;
72  int siciPin;
73  int muxPin;
74 
75  int ocd1FuncMode;
76  int ocd2FuncMode;
77 
78  int measRange;
79  int opMode;
80  int ocd1Mode;
81  int ocd2Mode;
82  int vrefExt;
83 
84  bool ll5V = true;
85 #ifdef ADC_RESOLUTION
86  int adcResol = ADC_RESOLUTION //if possible: highest possible resolution
87 #else
88  int adcResol = 10; //standard for Arduino UNO
89 #endif
90 
91  uint16_t configRegs[3];
92 
93  double swOcdThreshold = 0; //Alarm triggered if current exceeds this level [A]
94  double lastSwOcdValue = 0;
95  double swOcdCompHyst = 0;
96  bool swOcdTriggered = false;
97  bool lastOcd1PinState = HIGH;
98  bool lastOcd2PinState = HIGH;
99 
100  void (*_ocd1Function)(void);
101  void (*_ocd2Function)(void);
102  void (*_swOcdFunction)(void);
103 
104  bool sendConfig(void);
105 
106 };
107 
108 #endif
Definition: TLI4971.h:26
void configAdc(bool logicLevel5V, int adcResolution=-1)
Configurate ADC.
Definition: TLI4971.cpp:236
Definition: TLI4971.h:27
Definition: TLI4971.h:28
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:26
Definition: TLI4971.h:29
Definition: TLI4971.h:28
OCDDEGLITCH
Definition: TLI4971.h:28
bool setRatioGain(bool enable)
If this is enabled the sensitivity is ratio-metric to VDD respective to VREF in single-ended mode...
Definition: TLI4971.cpp:628
Definition: TLI4971.h:24
void ocdPolling(void)
If polling is used as OCD mode this function will perform the polling. Needs to be called repeatedly...
Definition: TLI4971.cpp:255
OCDTHR
Definition: TLI4971.h:29
bool setRatioOff(bool enable)
If this is enabled the ratio-metric offset behavior of the quiescent voltage is activated. Default is disabled.
Definition: TLI4971.cpp:653
Definition: TLI4971.h:29
Definition: TLI4971.h:28
bool setOpMode(int operatingMode)
Set operating mode of the sensor (refer to Programming guide).
Definition: TLI4971.cpp:427
Definition: TLI4971.h:29
double getLastSwOcdCurrent(void)
As soon as a Software OCD is triggered, the current value (> threshold) is stored. This function returns it.
Definition: TLI4971.cpp:305
Definition: TLI4971.h:27
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:29
Definition: TLI4971.h:28
OCDMODE
Definition: TLI4971.h:24
Definition: TLI4971.h:24
Definition: TLI4971.h:27
bool getOcd1State(void)
Reads state of ocd1-pin from sensor.
Definition: TLI4971.cpp:199
bool setVrefExt(int vrefExtVoltage)
Sets the reference voltage level. This can be used for Single Ended mode (setting needs to match exte...
Definition: TLI4971.cpp:602
Definition: TLI4971.h:30
VRefExt
Definition: TLI4971.h:30
Definition: TLI4971.h:28
Definition: TLI4971.h:26
Definition: TLI4971.h:29
bool registerSwOcdFunction(double currentLevel, void(*func)(void))
Register a handler, which shall be called when the sensor value exceeds a certain threshold...
Definition: TLI4971.cpp:378
Definition: TLI4971.h:30
TLI4971(int aout, int vref, int pwr, int sici, int ocd1, int ocd2, int mux, bool mc5V=true)
Current sensor instance constructor.
Definition: TLI4971.cpp:49
Definition: TLI4971.h:28
Definition: TLI4971.h:26
bool registerOcd2Function(int mode, void(*func)(void))
Register a handler which shall be called when the sensor triggeres OCD2.
Definition: TLI4971.cpp:350
Definition: SICI.h:46
bool setMeasRange(int measuringRange)
Sets the measurement Range of the sensor (refer to Programming Guide).
Definition: TLI4971.cpp:400
Definition: TLI4971.h:30
Definition: TLI4971.h:29
Definition: TLI4971.h:28
OPMODE
Definition: TLI4971.h:27
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:24
Definition: TLI4971.h:27
Definition: TLI4971.h:29
double read(void)
Reads sensor outputs and calculates current value. If Software OCD is used, this function can trigger...
Definition: TLI4971.cpp:171
void end(void)
Ends sensor library Turn off sensor supply.
Definition: TLI4971.cpp:159
bool registerOcd1Function(int mode, void(*func)(void))
Register a handler, which shall be called when the sensor triggeres OCD1.
Definition: TLI4971.cpp:321
Definition: TLI4971.h:29
Definition: TLI4971.h:20
bool getSwOcdState(void)
Get state of Software OCD.
Definition: TLI4971.cpp:223
bool setSwOcdCompHyst(double hysterese)
Set Hysteresis value for SW-OCD. Signal will be reset when current < threshold - hysteresis.
Definition: TLI4971.cpp:290
bool setOcdCompHyst(int threshold)
Sets the OCD hysteresis. OCD signals will reset if current < 20% of the provided threshold.
Definition: TLI4971.cpp:556
bool configOcd2(bool enable, int threshold=THR2_1, int deglitchTime=D0)
Configuration of OCD2.
Definition: TLI4971.cpp:506
~TLI4971(void)
Current sensor instance destructor . Reconfigurates pins to INPUT and ADC resolution to 8 Bit...
Definition: TLI4971.cpp:76
Definition: TLI4971.h:28
Definition: TLI4971.h:26
Definition: TLI4971.h:29
Definition: TLI4971.h:30
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:28
Definition: TLI4971.h:26
bool getOcd2State(void)
Reads state of ocd2-pin from sensor.
Definition: TLI4971.cpp:211
bool reset(void)
Resets sensor to factory settings.
Definition: TLI4971.cpp:147
bool configOcd1(bool enable, int threshold=THR1_1, int deglitchTime=D0)
Configuration of OCD1.
Definition: TLI4971.cpp:454
Definition: TLI4971.h:29
MEASRANGE
Definition: TLI4971.h:26
Definition: TLI4971.h:28
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:29
Definition: TLI4971.h:28
Definition: TLI4971.h:30
bool begin(void)
Turn on sensor supply, initialy reads sensor configuration and checks if sensor can be configurated...
Definition: TLI4971.cpp:91