Skip to content

Commit 7ecf1b7

Browse files
committed
forgotten offest exchange when exchanging pins in current align)
1 parent d9279b0 commit 7ecf1b7

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/current_sense/InlineCurrentSense.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,19 @@ int InlineCurrentSense::driverAlign(float voltage){
104104
int tmp_pinA = pinA;
105105
pinA = pinB;
106106
pinB = tmp_pinA;
107+
float tmp_offsetA = offset_ia;
108+
offset_ia = offset_ib;
109+
offset_ib = tmp_offsetA;
107110
gain_a *= _sign(c.b);
108111
exit_flag = 2; // signal that pins have been switched
109112
}else if(_isset(pinC) && ac_ratio < 0.7f ){ // should be ~0.5
110113
// switch phase A and C
111114
int tmp_pinA = pinA;
112115
pinA = pinC;
113116
pinC= tmp_pinA;
117+
float tmp_offsetA = offset_ia;
118+
offset_ia = offset_ic;
119+
offset_ic = tmp_offsetA;
114120
gain_a *= _sign(c.c);
115121
exit_flag = 2;// signal that pins have been switched
116122
}else{
@@ -144,13 +150,19 @@ int InlineCurrentSense::driverAlign(float voltage){
144150
int tmp_pinB = pinB;
145151
pinB = pinA;
146152
pinA = tmp_pinB;
153+
float tmp_offsetB = offset_ib;
154+
offset_ib = offset_ia;
155+
offset_ia = tmp_offsetB;
147156
gain_b *= _sign(c.a);
148157
exit_flag = 2; // signal that pins have been switched
149158
}else if(_isset(pinC) && bc_ratio < 0.7f ){ // should be ~0.5
150159
// switch phase A and C
151160
int tmp_pinB = pinB;
152161
pinB = pinC;
153162
pinC = tmp_pinB;
163+
float tmp_offsetB = offset_ib;
164+
offset_ib = offset_ic;
165+
offset_ic = tmp_offsetB;
154166
gain_b *= _sign(c.c);
155167
exit_flag = 2; // signal that pins have been switched
156168
}else{
@@ -185,13 +197,19 @@ int InlineCurrentSense::driverAlign(float voltage){
185197
int tmp_pinC = pinC;
186198
pinC = pinA;
187199
pinA = tmp_pinC;
200+
float tmp_offsetC = offset_ic;
201+
offset_ic = offset_ia;
202+
offset_ia = tmp_offsetC;
188203
gain_c *= _sign(c.a);
189204
exit_flag = 2; // signal that pins have been switched
190205
}else if(_isset(pinB) && cb_ratio < 0.7f ){ // should be ~0.5
191206
// switch phase B and C
192207
int tmp_pinC = pinC;
193208
pinC = pinB;
194209
pinB = tmp_pinC;
210+
float tmp_offsetC = offset_ic;
211+
offset_ic = offset_ib;
212+
offset_ib = tmp_offsetC;
195213
gain_c *= _sign(c.b);
196214
exit_flag = 2; // signal that pins have been switched
197215
}else{

src/current_sense/LowsideCurrentSense.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int LowsideCurrentSense::init(){
3636
}
3737
// Function finding zero offsets of the ADC
3838
void LowsideCurrentSense::calibrateOffsets(){
39-
const int calibration_rounds = 1000;
39+
const int calibration_rounds = 2000;
4040

4141
// find adc offset = zero current voltage
4242
offset_ia = 0;
@@ -105,13 +105,19 @@ int LowsideCurrentSense::driverAlign(float voltage){
105105
int tmp_pinA = pinA;
106106
pinA = pinB;
107107
pinB = tmp_pinA;
108+
float tmp_offsetA = offset_ia;
109+
offset_ia = offset_ib;
110+
offset_ib = tmp_offsetA;
108111
gain_a *= _sign(c.b);
109112
exit_flag = 2; // signal that pins have been switched
110113
}else if(_isset(pinC) && ac_ratio < 0.7f ){ // should be ~0.5
111114
// switch phase A and C
112115
int tmp_pinA = pinA;
113116
pinA = pinC;
114117
pinC= tmp_pinA;
118+
float tmp_offsetA = offset_ia;
119+
offset_ia = offset_ic;
120+
offset_ic = tmp_offsetA;
115121
gain_a *= _sign(c.c);
116122
exit_flag = 2;// signal that pins have been switched
117123
}else{
@@ -145,13 +151,19 @@ int LowsideCurrentSense::driverAlign(float voltage){
145151
int tmp_pinB = pinB;
146152
pinB = pinA;
147153
pinA = tmp_pinB;
154+
float tmp_offsetB = offset_ib;
155+
offset_ib = offset_ia;
156+
offset_ia = tmp_offsetB;
148157
gain_b *= _sign(c.a);
149158
exit_flag = 2; // signal that pins have been switched
150159
}else if(_isset(pinC) && bc_ratio < 0.7f ){ // should be ~0.5
151160
// switch phase A and C
152161
int tmp_pinB = pinB;
153162
pinB = pinC;
154163
pinC = tmp_pinB;
164+
float tmp_offsetB = offset_ib;
165+
offset_ib = offset_ic;
166+
offset_ic = tmp_offsetB;
155167
gain_b *= _sign(c.c);
156168
exit_flag = 2; // signal that pins have been switched
157169
}else{
@@ -186,13 +198,19 @@ int LowsideCurrentSense::driverAlign(float voltage){
186198
int tmp_pinC = pinC;
187199
pinC = pinA;
188200
pinA = tmp_pinC;
201+
float tmp_offsetC = offset_ic;
202+
offset_ic = offset_ia;
203+
offset_ia = tmp_offsetC;
189204
gain_c *= _sign(c.a);
190205
exit_flag = 2; // signal that pins have been switched
191206
}else if(_isset(pinB) && cb_ratio < 0.7f ){ // should be ~0.5
192207
// switch phase B and C
193208
int tmp_pinC = pinC;
194209
pinC = pinB;
195210
pinB = tmp_pinC;
211+
float tmp_offsetC = offset_ic;
212+
offset_ic = offset_ib;
213+
offset_ib = tmp_offsetC;
196214
gain_c *= _sign(c.b);
197215
exit_flag = 2; // signal that pins have been switched
198216
}else{

0 commit comments

Comments
 (0)