Skip to content

Commit c12a246

Browse files
author
Richard Unger
committed
add constructor taking mV per Amp to current sense
1 parent 0275a32 commit c12a246

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/current_sense/InlineCurrentSense.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ InlineCurrentSense::InlineCurrentSense(float _shunt_resistor, float _gain, int _
1717
gain_a = volts_to_amps_ratio;
1818
gain_b = volts_to_amps_ratio;
1919
gain_c = volts_to_amps_ratio;
20-
}
20+
};
21+
22+
23+
InlineCurrentSense::InlineCurrentSense(float _mVpA, int _pinA, int _pinB, int _pinC){
24+
pinA = _pinA;
25+
pinB = _pinB;
26+
pinC = _pinC;
27+
28+
volts_to_amps_ratio = _mVpA / 1000.0f; // mV to amps
29+
// gains for each phase
30+
gain_a = volts_to_amps_ratio;
31+
gain_b = volts_to_amps_ratio;
32+
gain_c = volts_to_amps_ratio;
33+
};
34+
35+
2136

2237
// Inline sensor init function
2338
int InlineCurrentSense::init(){

src/current_sense/InlineCurrentSense.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class InlineCurrentSense: public CurrentSense{
2121
@param phC C phase adc pin (optional)
2222
*/
2323
InlineCurrentSense(float shunt_resistor, float gain, int pinA, int pinB, int pinC = NOT_SET);
24+
/**
25+
InlineCurrentSense class constructor
26+
@param mVpA mV per Amp ratio
27+
@param phA A phase adc pin
28+
@param phB B phase adc pin
29+
@param phC C phase adc pin (optional)
30+
*/
31+
InlineCurrentSense(float mVpA, int pinA, int pinB, int pinC = NOT_SET);
2432

2533
// CurrentSense interface implementing functions
2634
int init() override;

src/current_sense/LowsideCurrentSense.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ LowsideCurrentSense::LowsideCurrentSense(float _shunt_resistor, float _gain, int
1919
gain_c = volts_to_amps_ratio;
2020
}
2121

22+
23+
LowsideCurrentSense::LowsideCurrentSense(float _mVpA, int _pinA, int _pinB, int _pinC){
24+
pinA = _pinA;
25+
pinB = _pinB;
26+
pinC = _pinC;
27+
28+
volts_to_amps_ratio = _mVpA / 1000.0f; // mV to amps
29+
// gains for each phase
30+
gain_a = volts_to_amps_ratio;
31+
gain_b = volts_to_amps_ratio;
32+
gain_c = volts_to_amps_ratio;
33+
}
34+
35+
2236
// Lowside sensor init function
2337
int LowsideCurrentSense::init(){
2438
// configure ADC variables

src/current_sense/LowsideCurrentSense.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class LowsideCurrentSense: public CurrentSense{
2222
@param phC C phase adc pin (optional)
2323
*/
2424
LowsideCurrentSense(float shunt_resistor, float gain, int pinA, int pinB, int pinC = _NC);
25+
/**
26+
LowsideCurrentSense class constructor
27+
@param mVpA mV per Amp ratio
28+
@param phA A phase adc pin
29+
@param phB B phase adc pin
30+
@param phC C phase adc pin (optional)
31+
*/
32+
LowsideCurrentSense(float mVpA, int pinA, int pinB, int pinC = _NC);
2533

2634
// CurrentSense interface implementing functions
2735
int init() override;

0 commit comments

Comments
 (0)