Skip to content

Commit 3fff22a

Browse files
committed
inline to low-side for BG431B ESC1 and pid removed antiwindup comment
1 parent 673e509 commit 3fff22a

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

examples/hardware_specific_examples/B_G431B_ESC1/B_G431B_ESC1.ino

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Motor instance
88
BLDCMotor motor = BLDCMotor(11);
99
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);
10-
InlineCurrentSense currentSense = InlineCurrentSense(0.003, -64.0/7.0, OP1_OUT, OP2_OUT, OP3_OUT);
10+
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, OP1_OUT, OP2_OUT, OP3_OUT);
1111

1212

1313
// encoder instance
@@ -43,6 +43,8 @@ void setup() {
4343

4444
// current sensing
4545
currentSense.init();
46+
// no need for aligning
47+
currentSense.skip_align = true;
4648
motor.linkCurrentSense(&currentSense);
4749

4850
// aligning voltage [V]
@@ -97,15 +99,8 @@ float target_angle = 0;
9799

98100
void loop() {
99101
// main FOC algorithm function
100-
// the faster you run this function the better
101-
// Arduino UNO loop ~1kHz
102-
// Bluepill loop ~10kHz
103-
motor.loopFOC();
104102

105103
// Motion control function
106-
// velocity, position or voltage (defined in motor.controller)
107-
// this function can be run at much lower frequency than loopFOC() function
108-
// You can also use motor.move() and set the motor.target in the code
109104
motor.move(target_angle);
110105

111106
// function intended to be used with serial plotter to monitor motor variables

src/common/pid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ float PIDController::operator() (float error){
2828
float proportional = P * error;
2929
// Tustin transform of the integral part
3030
// u_ik = u_ik_1 + I*Ts/2*(ek + ek_1)
31-
// method uses the antiwindup Foxboro method : https://core.ac.uk/download/pdf/289952713.pdf
3231
float integral = integral_prev + I*Ts*0.5f*(error + error_prev);
3332
// antiwindup - limit the output
3433
integral = _constrain(integral, -limit, limit);

src/current_sense/LowsideCurrentSense.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ int LowsideCurrentSense::driverSync(BLDCDriver *driver){
7575
// 3 - success but gains inverted
7676
// 4 - success but pins reconfigured and gains inverted
7777
int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
78-
//gain_a *= -1;
79-
//gain_b *= -1;
80-
//gain_c *= -1;
81-
82-
/*
78+
8379
int exit_flag = 1;
8480
if(skip_align) return exit_flag;
8581

@@ -90,9 +86,9 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
9086
// read the current 100 times ( arbitrary number )
9187
for (int i = 0; i < 100; i++) {
9288
PhaseCurrent_s c1 = getPhaseCurrents();
93-
c.a = c.a*0.6 + 0.4f*c1.a;
94-
c.b = c.b*0.6 + 0.4f*c1.b;
95-
c.c = c.c*0.6 + 0.4f*c1.c;
89+
c.a = c.a*0.6f + 0.4f*c1.a;
90+
c.b = c.b*0.6f + 0.4f*c1.b;
91+
c.c = c.c*0.6f + 0.4f*c1.c;
9692
_delay(3);
9793
}
9894
driver->setPwm(0, 0, 0);
@@ -165,7 +161,7 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
165161
// read the adc voltage 500 times ( arbitrary number )
166162
for (int i = 0; i < 50; i++) {
167163
PhaseCurrent_s c1 = getPhaseCurrents();
168-
c.c = (c.c+c1.c)/50.0;
164+
c.c = (c.c+c1.c)/50.0f;
169165
}
170166
driver->setPwm(0, 0, 0);
171167
gain_c *= _sign(c.c);
@@ -180,6 +176,4 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
180176
// 4 - success but pins reconfigured and gains inverted
181177

182178
return exit_flag;
183-
*/
184-
return 1;
185179
}

src/current_sense/hardware_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,4 @@ float _readADCVoltageLowSide(const int pinA);
4343
*/
4444
void _driverSyncLowSide();
4545

46-
47-
void _startADC3PinConversionLowSide();
48-
4946
#endif

src/current_sense/hardware_specific/stm32g4_mcu.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ float _readADCVoltageInline(const int pin){
3434

3535
return raw_adc * _ADC_CONV;
3636
}
37+
// do the same for low side sensing
38+
float _readADCVoltageLowSide(const int pin){
39+
return _readADCVoltageInline(pin);
40+
}
3741

3842
void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
3943
// could this be replaced with LL_OPAMP calls??
@@ -108,6 +112,10 @@ void _configureADCInline(const int pinA,const int pinB,const int pinC){
108112
Error_Handler();
109113
}
110114
}
115+
// do the same for low side
116+
void _configureADCLowSide(const int pinA,const int pinB,const int pinC){
117+
_configureADCInline(pinA, pinB, pinC);
118+
}
111119

112120
extern "C" {
113121
void DMA1_Channel1_IRQHandler(void) {

0 commit comments

Comments
 (0)