Skip to content

Commit 802b478

Browse files
Merge pull request #253 from runger1101001/dev
add constructor taking mV per Amp to current sense
2 parents 0275a32 + 20af2d1 commit 802b478

File tree

12 files changed

+55
-10
lines changed

12 files changed

+55
-10
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777

7878
- arduino-boards-fqbn: STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE # nucleo one full example
7979
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
80-
sketch-names: single_full_control_example.ino, stm32_spi_alt_example.ino, sdouble_full_control_example.ino, stm32_current_control_low_side.ino
80+
sketch-names: single_full_control_example.ino, stm32_spi_alt_example.ino, double_full_control_example.ino, stm32_current_control_low_side.ino
8181

8282

8383
# Do not cancel all jobs / architectures if one job fails

examples/hardware_specific_examples/B_G431B_ESC1/B_G431B_ESC1.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Motor instance
88
BLDCMotor motor = BLDCMotor(11);
99
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
10-
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
10+
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
1111

1212

1313
// encoder instance

examples/hardware_specific_examples/SimpleFOC-PowerShield/version_v02/single_full_control_example/single_full_control_example.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void doA(){encoder.handleA();}
1212
void doB(){encoder.handleB();}
1313

1414
// inline current sensor instance
15-
InlineCurrentSense current_sense = InlineCurrentSense(0.001, 50.0, A0, A1);
15+
InlineCurrentSense current_sense = InlineCurrentSense(0.001f, 50.0f, A0, A1);
1616

1717
// commander communication instance
1818
Commander command = Commander(Serial);

examples/hardware_specific_examples/SimpleFOCShield/version_v2/double_full_control_example/double_full_control_example.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ void doB2(){encoder2.handleB();}
2424

2525
// inline current sensor instance
2626
// check if your board has R010 (0.01 ohm resistor) or R006 (0.006 mOhm resistor)
27-
InlineCurrentSense current_sense1 = InlineCurrentSense(0.01, 50.0, A0, A2);
27+
InlineCurrentSense current_sense1 = InlineCurrentSense(0.01f, 50.0f, A0, A2);
2828

2929
// inline current sensor instance
3030
// check if your board has R010 (0.01 ohm resistor) or R006 (0.006 mOhm resistor)
31-
InlineCurrentSense current_sense2 = InlineCurrentSense(0.01, 50.0, A1, A3);
31+
InlineCurrentSense current_sense2 = InlineCurrentSense(0.01f, 50.0f, A1, A3);
3232

3333
// commander communication instance
3434
Commander command = Commander(Serial);

examples/hardware_specific_examples/SimpleFOCShield/version_v2/single_full_control_example/single_full_control_example.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void doB(){encoder.handleB();}
1313

1414
// inline current sensor instance
1515
// check if your board has R010 (0.01 ohm resistor) or R006 (0.006 mOhm resistor)
16-
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
16+
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);
1717

1818
// commander communication instance
1919
Commander command = Commander(Serial);

examples/hardware_specific_examples/SimpleFOCShield/version_v3/single_full_control_example/single_full_control_example.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void doB(){encoder.handleB();}
1313

1414
// inline current sensor instance
1515
// ACS712-05B has the resolution of 0.185mV per Amp
16-
InlineCurrentSense current_sense = InlineCurrentSense(1, 0.185, A0, A2);
16+
InlineCurrentSense current_sense = InlineCurrentSense(1.0f, 0.185f, A0, A2);
1717

1818
// commander communication instance
1919
Commander command = Commander(Serial);

examples/motion_control/torque_control/encoder/current_control/current_control.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void doA(){encoder.handleA();}
1717
void doB(){encoder.handleB();}
1818

1919
// current sensor
20-
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
20+
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);
2121

2222
// current set point variable
2323
float target_current = 0;

examples/utils/current_sense_test/inline_current_sense_test/inline_current_sense_test.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// shunt resistor value
88
// gain value
99
// pins phase A,B, (C optional)
10-
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
10+
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);
1111

1212

1313
void setup() {

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)