File tree Expand file tree Collapse file tree 3 files changed +25
-15
lines changed Expand file tree Collapse file tree 3 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ float CurrentSense::getDCCurrent(float motor_electrical_angle){
17
17
i_alpha = current.a ;
18
18
i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b ;
19
19
}else {
20
- i_alpha = 2 *(current.a - (current.b - current.c ))/3.0 ;
21
- i_beta = _2_SQRT3 *( current.b - current.c );
20
+ // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed.
21
+ float mid = (1 .f /3 ) * (current.a + current.b + current.c );
22
+ float a = current.a - mid;
23
+ float b = current.b - mid;
24
+ i_alpha = a;
25
+ i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
22
26
}
23
27
24
28
// if motor angle provided function returns signed value of the current
@@ -44,9 +48,13 @@ DQCurrent_s CurrentSense::getFOCCurrents(float angle_el){
44
48
// if only two measured currents
45
49
i_alpha = current.a ;
46
50
i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b ;
47
- }else {
48
- i_alpha = 0.6666667 *(current.a - (current.b - current.c ));
49
- i_beta = _2_SQRT3 *( current.b - current.c );
51
+ } else {
52
+ // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed.
53
+ float mid = (1 .f /3 ) * (current.a + current.b + current.c );
54
+ float a = current.a - mid;
55
+ float b = current.b - mid;
56
+ i_alpha = a;
57
+ i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
50
58
}
51
59
52
60
// calculate park transform
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)
Original file line number Diff line number Diff line change @@ -29,9 +29,9 @@ class InlineCurrentSense: public CurrentSense{
29
29
// ADC measuremnet gain for each phase
30
30
// support for different gains for different phases of more commonly - inverted phase currents
31
31
// this should be automated later
32
- int gain_a; // !< phase A gain
33
- int gain_b; // !< phase B gain
34
- int gain_c; // !< phase C gain
32
+ float gain_a; // !< phase A gain
33
+ float gain_b; // !< phase B gain
34
+ float gain_c; // !< phase C gain
35
35
36
36
private:
37
37
You can’t perform that action at this time.
0 commit comments