Skip to content

Commit fd78d2e

Browse files
committed
Fix consistency error in calibrateOffsets.
1 parent ee2dfde commit fd78d2e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/current_sense/InlineCurrentSense.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ void InlineCurrentSense::init(){
2828
}
2929
// Function finding zero offsets of the ADC
3030
void InlineCurrentSense::calibrateOffsets(){
31+
const int calibration_rounds = 1000;
32+
3133
// find adc offset = zero current voltage
32-
offset_ia =0;
33-
offset_ib= 0;
34-
offset_ic= 0;
34+
offset_ia = 0;
35+
offset_ib = 0;
36+
offset_ic = 0;
3537
// read the adc voltage 1000 times ( arbitrary number )
36-
for (int i = 0; i < 1000; i++) {
38+
for (int i = 0; i < calibration_rounds; i++) {
3739
offset_ia += _readADCVoltage(pinA);
3840
offset_ib += _readADCVoltage(pinB);
3941
if(_isset(pinC)) offset_ic += _readADCVoltage(pinC);
4042
_delay(1);
4143
}
4244
// calculate the mean offsets
43-
offset_ia = offset_ia / 1000.0;
44-
offset_ib = offset_ib / 1000.0;
45-
if(_isset(pinC)) offset_ic = offset_ic / 500.0;
45+
offset_ia = offset_ia / calibration_rounds;
46+
offset_ib = offset_ib / calibration_rounds;
47+
if(_isset(pinC)) offset_ic = offset_ic / calibration_rounds;
4648
}
4749

4850
// read all three phase currents (if possible 2 or 3)

0 commit comments

Comments
 (0)