TLI4971 Current Sensor 1.1.2
C++ library of Infineons Magnetic Hall TLI4971 Current Sensor
 
Loading...
Searching...
No Matches
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
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 };
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};
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:21
bool registerOcd2Function(int mode, void(*func)(void))
Register a handler which shall be called when the sensor triggeres OCD2.
Definition TLI4971.cpp:353
bool registerOcd1Function(int mode, void(*func)(void))
Register a handler, which shall be called when the sensor triggeres OCD1.
Definition TLI4971.cpp:324
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:605
double read(void)
Reads sensor outputs and calculates current value. If Software OCD is used, this function can trigger...
Definition TLI4971.cpp:174
OCDDEGLITCH
Definition TLI4971.h:28
@ D6
Definition TLI4971.h:28
@ D1
Definition TLI4971.h:28
@ D2
Definition TLI4971.h:28
@ D3
Definition TLI4971.h:28
@ D7
Definition TLI4971.h:28
@ D10
Definition TLI4971.h:28
@ D4
Definition TLI4971.h:28
@ D15
Definition TLI4971.h:28
@ D13
Definition TLI4971.h:28
@ D8
Definition TLI4971.h:28
@ D12
Definition TLI4971.h:28
@ D9
Definition TLI4971.h:28
@ D0
Definition TLI4971.h:28
@ D11
Definition TLI4971.h:28
@ D14
Definition TLI4971.h:28
@ D5
Definition TLI4971.h:28
~TLI4971(void)
Current sensor instance destructor . Reconfigurates pins to INPUT and ADC resolution to 8 Bit
Definition TLI4971.cpp:79
OPMODE
Definition TLI4971.h:27
@ S_ENDED
Definition TLI4971.h:27
@ SD_UNI
Definition TLI4971.h:27
@ SD_BID
Definition TLI4971.h:27
@ FD
Definition TLI4971.h:27
double getLastSwOcdCurrent(void)
As soon as a Software OCD is triggered, the current value (> threshold) is stored....
Definition TLI4971.cpp:308
bool configOcd1(bool enable, int threshold=THR1_1, int deglitchTime=D0)
Configuration of OCD1.
Definition TLI4971.cpp:457
void end(void)
Ends sensor library Turn off sensor supply.
Definition TLI4971.cpp:162
bool reset(void)
Resets sensor to factory settings.
Definition TLI4971.cpp:150
bool setOcdCompHyst(int threshold)
Sets the OCD hysteresis. OCD signals will reset if current < 20% of the provided threshold.
Definition TLI4971.cpp:559
bool begin(void)
Turn on sensor supply, initialy reads sensor configuration and checks if sensor can be configurated.
Definition TLI4971.cpp:94
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:631
MEASRANGE
Definition TLI4971.h:26
@ FSR75
Definition TLI4971.h:26
@ FSR100
Definition TLI4971.h:26
@ FSR25
Definition TLI4971.h:26
@ FSR120
Definition TLI4971.h:26
@ FSR37_5
Definition TLI4971.h:26
@ FSR50
Definition TLI4971.h:26
void configAdc(bool logicLevel5V, int adcResolution=-1)
Configurate ADC.
Definition TLI4971.cpp:239
bool getOcd2State(void)
Reads state of ocd2-pin from sensor.
Definition TLI4971.cpp:214
bool getSwOcdState(void)
Get state of Software OCD.
Definition TLI4971.cpp:226
bool setSwOcdCompHyst(double hysterese)
Set Hysteresis value for SW-OCD. Signal will be reset when current < threshold - hysteresis.
Definition TLI4971.cpp:293
VRefExt
Definition TLI4971.h:30
@ V1_2
Definition TLI4971.h:30
@ V2_5
Definition TLI4971.h:30
@ V1_8
Definition TLI4971.h:30
@ V1_65
Definition TLI4971.h:30
@ V1_5
Definition TLI4971.h:30
bool setRatioOff(bool enable)
If this is enabled the ratio-metric offset behavior of the quiescent voltage is activated....
Definition TLI4971.cpp:656
OCDMODE
Definition TLI4971.h:24
@ POLLING
Definition TLI4971.h:24
@ NONE
Definition TLI4971.h:24
@ INTERRUPT
Definition TLI4971.h:24
bool configOcd2(bool enable, int threshold=THR2_1, int deglitchTime=D0)
Configuration of OCD2.
Definition TLI4971.cpp:509
void ocdPolling(void)
If polling is used as OCD mode this function will perform the polling. Needs to be called repeatedly,...
Definition TLI4971.cpp:258
OCDTHR
Definition TLI4971.h:29
@ THR2_7
Definition TLI4971.h:29
@ THR2_8
Definition TLI4971.h:29
@ THR2_5
Definition TLI4971.h:29
@ THR2_2
Definition TLI4971.h:29
@ THR2_3
Definition TLI4971.h:29
@ THR1_7
Definition TLI4971.h:29
@ THR1_6
Definition TLI4971.h:29
@ THR1_4
Definition TLI4971.h:29
@ THR1_3
Definition TLI4971.h:29
@ THR2_6
Definition TLI4971.h:29
@ THR1_2
Definition TLI4971.h:29
@ THR1_5
Definition TLI4971.h:29
@ THR1_1
Definition TLI4971.h:29
@ THR2_4
Definition TLI4971.h:29
@ THR1_8
Definition TLI4971.h:29
@ THR2_1
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:381
bool setOpMode(int operatingMode)
Set operating mode of the sensor (refer to Programming guide).
Definition TLI4971.cpp:430
bool setMeasRange(int measuringRange)
Sets the measurement Range of the sensor (refer to Programming Guide).
Definition TLI4971.cpp:403
bool getOcd1State(void)
Reads state of ocd1-pin from sensor.
Definition TLI4971.cpp:202
Definition SICI.h:47