Skip to content

Commit 4eec52d

Browse files
committed
Fix NaN-problem after lost tracking on some motors
1 parent a8f989e commit 4eec52d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

hwconf/hw_100_500.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@
216216
#define READ_HALL2() palReadPad(HW_HALL_ENC_GPIO2, HW_HALL_ENC_PIN2)
217217
#define READ_HALL3() palReadPad(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3)
218218

219-
// Override dead time. See the stm32f4 reference manual for calculating this value.
220-
#define HW_DEAD_TIME_NSEC 660.0
219+
#define HW_DEAD_TIME_NSEC 1000.0
221220

222221
// Default setting overrides
223222
#ifndef MCCONF_L_MIN_VOLTAGE

mcpwm_foc.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -2765,6 +2765,9 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
27652765
observer_update(motor_now->m_motor_state.v_alpha, motor_now->m_motor_state.v_beta,
27662766
motor_now->m_motor_state.i_alpha, motor_now->m_motor_state.i_beta, dt,
27672767
&motor_now->m_observer_x1, &motor_now->m_observer_x2, &motor_now->m_phase_now_observer, motor_now);
2768+
2769+
// Compensate from the phase lag caused by the switching frequency. This is important for motors
2770+
// that run on high ERPM compared to the switching frequency.
27682771
motor_now->m_phase_now_observer += motor_now->m_pll_speed * dt * 0.5;
27692772
utils_norm_angle_rad((float*)&motor_now->m_phase_now_observer);
27702773
}
@@ -3781,8 +3784,8 @@ static void control_current(volatile motor_all_state_t *motor, float dt) {
37813784
float dec_bemf = 0.0;
37823785

37833786
if (motor->m_control_mode < CONTROL_MODE_HANDBRAKE && conf_now->foc_cc_decoupling != FOC_CC_DECOUPLING_DISABLED) {
3784-
float lq = conf_now->foc_motor_l + conf_now->foc_motor_ld_lq_diff / 2.0;
3785-
float ld = conf_now->foc_motor_l - conf_now->foc_motor_ld_lq_diff / 2.0;
3787+
float lq = conf_now->foc_motor_l + conf_now->foc_motor_ld_lq_diff * 0.5;
3788+
float ld = conf_now->foc_motor_l - conf_now->foc_motor_ld_lq_diff * 0.5;
37863789

37873790
switch (conf_now->foc_cc_decoupling) {
37883791
case FOC_CC_DECOUPLING_CROSS:

utils.c

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ float utils_fast_atan2(float y, float x) {
323323
angle = ((0.1963 * rsq) - 0.9817) * r + (3.0 * M_PI / 4.0);
324324
}
325325

326+
UTILS_NAN_ZERO(angle);
327+
326328
if (y < 0) {
327329
return(-angle);
328330
} else {

0 commit comments

Comments
 (0)