File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -28,21 +28,23 @@ void InlineCurrentSense::init(){
28
28
}
29
29
// Function finding zero offsets of the ADC
30
30
void InlineCurrentSense::calibrateOffsets (){
31
+ const int calibration_rounds = 1000 ;
32
+
31
33
// 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 ;
35
37
// 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++) {
37
39
offset_ia += _readADCVoltage (pinA);
38
40
offset_ib += _readADCVoltage (pinB);
39
41
if (_isset (pinC)) offset_ic += _readADCVoltage (pinC);
40
42
_delay (1 );
41
43
}
42
44
// 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 ;
46
48
}
47
49
48
50
// read all three phase currents (if possible 2 or 3)
You can’t perform that action at this time.
0 commit comments