@@ -109,7 +109,8 @@ typedef struct {
109
109
mc_state m_state ;
110
110
mc_control_mode m_control_mode ;
111
111
motor_state_t m_motor_state ;
112
- int m_curr_unbalance ;
112
+ float m_curr_unbalance ;
113
+ float m_currents_adc [3 ];
113
114
bool m_phase_override ;
114
115
float m_phase_now_override ;
115
116
float m_duty_cycle_set ;
@@ -594,21 +595,19 @@ void mcpwm_foc_init(volatile mc_configuration *conf_m1, volatile mc_configuratio
594
595
DCCAL_OFF ();
595
596
596
597
if (m_motor_1 .m_conf -> foc_offsets_cal_on_boot ) {
597
- m_motor_1 .m_conf -> foc_offsets_current [0 ] = 2048 ;
598
- m_motor_1 .m_conf -> foc_offsets_current [1 ] = 2048 ;
599
- m_motor_1 .m_conf -> foc_offsets_current [2 ] = 2048 ;
598
+ for (int i = 0 ;i < 3 ;i ++ ) {
599
+ m_motor_1 .m_conf -> foc_offsets_voltage [i ] = 0.0 ;
600
+ m_motor_1 .m_conf -> foc_offsets_voltage_undriven [i ] = 0.0 ;
601
+ m_motor_1 .m_conf -> foc_offsets_current [i ] = 2048 ;
602
+
600
603
#ifdef HW_HAS_DUAL_MOTORS
601
- m_motor_2 .m_conf -> foc_offsets_current [ 0 ] = 2048 ;
602
- m_motor_2 .m_conf -> foc_offsets_current [ 1 ] = 2048 ;
603
- m_motor_2 .m_conf -> foc_offsets_current [2 ] = 2048 ;
604
+ m_motor_2 .m_conf -> foc_offsets_voltage [ i ] = 0.0 ;
605
+ m_motor_2 .m_conf -> foc_offsets_voltage_undriven [ i ] = 0.0 ;
606
+ m_motor_2 .m_conf -> foc_offsets_current [i ] = 2048 ;
604
607
#endif
608
+ }
605
609
606
610
mcpwm_foc_dc_cal (false);
607
-
608
- conf_general_store_mc_configuration ((mc_configuration * )m_motor_1 .m_conf , false);
609
- #ifdef HW_HAS_DUAL_MOTORS
610
- conf_general_store_mc_configuration ((mc_configuration * )m_motor_2 .m_conf , true);
611
- #endif
612
611
} else {
613
612
m_dccal_done = true;
614
613
}
@@ -1211,7 +1210,7 @@ float mcpwm_foc_get_abs_motor_current(void) {
1211
1210
* The magnitude of the phase currents unbalance.
1212
1211
*/
1213
1212
float mcpwm_foc_get_abs_motor_current_unbalance (void ) {
1214
- return ( float )( motor_now ()-> m_curr_unbalance ) * FAC_CURRENT ;
1213
+ return motor_now ()-> m_curr_unbalance * FAC_CURRENT ;
1215
1214
}
1216
1215
1217
1216
/**
@@ -2096,7 +2095,7 @@ int mcpwm_foc_dc_cal(bool cal_undriven) {
2096
2095
2097
2096
// Measure driven offsets
2098
2097
2099
- const float samples = 500 .0 ;
2098
+ const float samples = 1000 .0 ;
2100
2099
float current_sum [3 ] = {0.0 , 0.0 , 0.0 };
2101
2100
float voltage_sum [3 ] = {0.0 , 0.0 , 0.0 };
2102
2101
@@ -2126,10 +2125,10 @@ int mcpwm_foc_dc_cal(bool cal_undriven) {
2126
2125
chThdSleepMilliseconds (10 );
2127
2126
2128
2127
for (float i = 0 ;i < samples ;i ++ ) {
2129
- current_sum [0 ] += GET_CURRENT1 () ;
2128
+ current_sum [0 ] += m_motor_1 . m_currents_adc [ 0 ] ;
2130
2129
voltage_sum [0 ] += ADC_VOLTS (ADC_IND_SENS1 );
2131
2130
#ifdef HW_HAS_DUAL_MOTORS
2132
- current_sum_m2 [0 ] += GET_CURRENT1_M2 () ;
2131
+ current_sum_m2 [0 ] += m_motor_2 . m_currents_adc [ 0 ] ;
2133
2132
voltage_sum_m2 [0 ] += ADC_VOLTS (ADC_IND_SENS4 );
2134
2133
#endif
2135
2134
chThdSleep (1 );
@@ -2155,10 +2154,10 @@ int mcpwm_foc_dc_cal(bool cal_undriven) {
2155
2154
chThdSleep (1 );
2156
2155
2157
2156
for (float i = 0 ;i < samples ;i ++ ) {
2158
- current_sum [1 ] += GET_CURRENT2 () ;
2157
+ current_sum [1 ] += m_motor_1 . m_currents_adc [ 1 ] ;
2159
2158
voltage_sum [1 ] += ADC_VOLTS (ADC_IND_SENS2 );
2160
2159
#ifdef HW_HAS_DUAL_MOTORS
2161
- current_sum_m2 [1 ] += GET_CURRENT2_M2 () ;
2160
+ current_sum_m2 [1 ] += m_motor_2 . m_currents_adc [ 1 ] ;
2162
2161
voltage_sum_m2 [1 ] += ADC_VOLTS (ADC_IND_SENS5 );
2163
2162
#endif
2164
2163
chThdSleep (1 );
@@ -2184,10 +2183,10 @@ int mcpwm_foc_dc_cal(bool cal_undriven) {
2184
2183
chThdSleep (1 );
2185
2184
2186
2185
for (float i = 0 ;i < samples ;i ++ ) {
2187
- current_sum [2 ] += GET_CURRENT3 () ;
2186
+ current_sum [2 ] += m_motor_1 . m_currents_adc [ 2 ] ;
2188
2187
voltage_sum [2 ] += ADC_VOLTS (ADC_IND_SENS3 );
2189
2188
#ifdef HW_HAS_DUAL_MOTORS
2190
- current_sum_m2 [2 ] += GET_CURRENT3_M2 () ;
2189
+ current_sum_m2 [2 ] += m_motor_2 . m_currents_adc [ 2 ] ;
2191
2190
voltage_sum_m2 [2 ] += ADC_VOLTS (ADC_IND_SENS6 );
2192
2191
#endif
2193
2192
chThdSleep (1 );
@@ -2394,8 +2393,8 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
2394
2393
#endif
2395
2394
2396
2395
#ifdef HW_HAS_DUAL_MOTORS
2397
- int curr0 = 0 ;
2398
- int curr1 = 0 ;
2396
+ float curr0 = 0 ;
2397
+ float curr1 = 0 ;
2399
2398
2400
2399
if (is_second_motor ) {
2401
2400
curr0 = GET_CURRENT1_M2 ();
@@ -2424,6 +2423,14 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
2424
2423
#endif
2425
2424
#endif
2426
2425
2426
+ motor_now -> m_currents_adc [0 ] = curr0 ;
2427
+ motor_now -> m_currents_adc [1 ] = curr1 ;
2428
+ #ifdef HW_HAS_3_SHUNTS
2429
+ motor_now -> m_currents_adc [2 ] = curr2 ;
2430
+ #else
2431
+ motor_now -> m_currents_adc [2 ] = 0.0 ;
2432
+ #endif
2433
+
2427
2434
curr0 -= conf_now -> foc_offsets_current [0 ];
2428
2435
curr1 -= conf_now -> foc_offsets_current [1 ];
2429
2436
#ifdef HW_HAS_3_SHUNTS
0 commit comments