|
|
@@ -194,7 +194,7 @@ static bool mc_detect_vbus_mode(void) {
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-static void _mc_internal_init(u8 mode, bool start) {
|
|
|
+static void mc_internal_init(u8 mode, bool start) {
|
|
|
motor.mode = mode;
|
|
|
motor.throttle = 0;
|
|
|
motor.b_start = start;
|
|
|
@@ -212,7 +212,9 @@ static void _mc_internal_init(u8 mode, bool start) {
|
|
|
motor.b_limit_pending = false;
|
|
|
motor.f_epm_trq = 0;
|
|
|
motor.f_epm_vel = 0;
|
|
|
+ motor.vbus_le_cnt = motor.vbus_he_cnt = 0;
|
|
|
motor.s_vbus_hw_min = mc_conf()->c.min_dc_vol;
|
|
|
+ motor.s_vbus_hw_max = mc_conf()->c.max_dc_vol;
|
|
|
}
|
|
|
|
|
|
static void _led_off_timer_handler(shark_timer_t *t) {
|
|
|
@@ -234,6 +236,7 @@ static void mc_gear_mode_set(void) {
|
|
|
}
|
|
|
|
|
|
void mc_init(void) {
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
fan_pwm_init();
|
|
|
adc_init();
|
|
|
pwm_3phase_init();
|
|
|
@@ -301,7 +304,8 @@ float mc_gear_max_torque(s16 vel, u8 gear_n) {
|
|
|
|
|
|
/* 必须立即停机 */
|
|
|
bool mc_critical_need_stop(void) {
|
|
|
- u32 mask = FOC_Cri_Err_Mask(FOC_CRIT_IDC_OV) | FOC_Cri_Err_Mask(FOC_CRIT_Angle_Err) | FOC_Cri_Err_Mask(FOC_CRIT_Vol_HW_Err);
|
|
|
+ u32 mask = FOC_Cri_Err_Mask(FOC_CRIT_IDC_OV) | FOC_Cri_Err_Mask(FOC_CRIT_Angle_Err) | FOC_Cri_Err_Mask(FOC_CRIT_Phase_Err) |
|
|
|
+ FOC_Cri_Err_Mask(FOC_CRIT_Vol_HW_Err) | FOC_Cri_Err_Mask(FOC_CRIT_OV_Vol_Err);
|
|
|
u32 err = motor.n_CritiCalErrMask & mask;
|
|
|
return (err != 0);
|
|
|
}
|
|
|
@@ -377,7 +381,7 @@ bool mc_start(u8 mode) {
|
|
|
|
|
|
u32 mask = cpu_enter_critical();
|
|
|
|
|
|
- _mc_internal_init(mode, true);
|
|
|
+ mc_internal_init(mode, true);
|
|
|
throttle_torque_reset();
|
|
|
motor_encoder_start(true);
|
|
|
mot_contrl_start(&motor.controller, mode);
|
|
|
@@ -429,7 +433,7 @@ bool mc_stop(void) {
|
|
|
}
|
|
|
|
|
|
u32 mask = cpu_enter_critical();
|
|
|
- _mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
|
mot_contrl_stop(&motor.controller);
|
|
|
@@ -906,7 +910,7 @@ static void _encoder_zero_off_timer_handler(shark_timer_t *t){
|
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
|
mot_contrl_stop(&motor.controller);
|
|
|
- _mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
motor.b_calibrate = false;
|
|
|
}
|
|
|
|
|
|
@@ -920,7 +924,7 @@ bool mc_encoder_zero_calibrate(s16 vd) {
|
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
|
mot_contrl_stop(&motor.controller);
|
|
|
- _mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
motor.b_calibrate = false;
|
|
|
motor.b_ignor_throttle = false;
|
|
|
}
|
|
|
@@ -933,7 +937,7 @@ bool mc_encoder_zero_calibrate(s16 vd) {
|
|
|
mot_contrl_set_error(&motor.controller, FOC_Have_CritiCal_Err);
|
|
|
return false;
|
|
|
}
|
|
|
- _mc_internal_init(CTRL_MODE_OPEN, true);
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, true);
|
|
|
motor.b_calibrate = true;
|
|
|
pwm_turn_on_low_side();
|
|
|
task_udelay(500);
|
|
|
@@ -1179,7 +1183,7 @@ void MC_Protect_IRQHandler(void){
|
|
|
}
|
|
|
mc_set_critical_error(FOC_CRIT_Phase_Err);
|
|
|
mc_save_err_runtime();
|
|
|
- _mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
+ mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
|
mot_contrl_stop(&motor.controller);
|
|
|
@@ -1195,12 +1199,10 @@ void motor_debug(void) {
|
|
|
sys_debug("err3: %f, %d, %d, %d, %d\n", (float)mc_error.ibus_x10/10.0f, mc_error.sensorless_rpm, mc_error.mos_temp, mc_error.mot_temp, mc_error.enc_error);
|
|
|
}
|
|
|
|
|
|
-static void motor_vbus_crit_low(s16 curr_vbus) {
|
|
|
- static u16 _vbus_e_count = 0;
|
|
|
-
|
|
|
- if (curr_vbus < motor.s_vbus_hw_min) {
|
|
|
- _vbus_e_count ++;
|
|
|
- if (_vbus_e_count >= 2) {
|
|
|
+static void motor_vbus_crit_check(s16 curr_vbus) {
|
|
|
+ if (curr_vbus <= motor.s_vbus_hw_min) {
|
|
|
+ motor.vbus_le_cnt ++;
|
|
|
+ if (motor.vbus_le_cnt >= 2) {
|
|
|
if (mot_contrl_is_start(&motor.controller)) {
|
|
|
pwm_disable_channel();
|
|
|
mc_save_err_runtime();
|
|
|
@@ -1213,14 +1215,31 @@ static void motor_vbus_crit_low(s16 curr_vbus) {
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
- _vbus_e_count = 0;
|
|
|
+ motor.vbus_le_cnt = 0;
|
|
|
+ }
|
|
|
+ if (curr_vbus >= motor.s_vbus_hw_max) {
|
|
|
+ motor.vbus_he_cnt ++;
|
|
|
+ if (motor.vbus_he_cnt >= 2) {
|
|
|
+ if (mot_contrl_is_start(&motor.controller)) {
|
|
|
+ pwm_disable_channel();
|
|
|
+ mc_save_err_runtime();
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
+ }
|
|
|
+ if (mc_set_critical_error(FOC_CRIT_OV_Vol_Err)) {
|
|
|
+ if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
|
|
|
+ mc_crit_err_add_s16(FOC_CRIT_OV_Vol_Err, curr_vbus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ motor.vbus_he_cnt = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void TIMER_UP_IRQHandler(void){
|
|
|
if (!motor.b_start && !mot_contrl_is_start(&motor.controller)) {
|
|
|
motor_encoder_update(false);
|
|
|
- motor_vbus_crit_low((s16)get_vbus_int());
|
|
|
+ motor_vbus_crit_check((s16)get_vbus_int());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1253,7 +1272,7 @@ void ADC_IRQHandler(void) {
|
|
|
iab_w_count ++;
|
|
|
}
|
|
|
#endif
|
|
|
- motor_vbus_crit_low((s16)sample_vbus_raw()); //need fast detect vbus very low, to stop the motor
|
|
|
+ motor_vbus_crit_check((s16)sample_vbus_raw()); //need fast detect vbus very low, to stop the motor
|
|
|
float vd, vq;
|
|
|
if (motor.b_ind_start) {
|
|
|
mot_params_high_freq_inject();
|
|
|
@@ -1502,11 +1521,14 @@ static bool mc_can_stop_foc(void) {
|
|
|
}
|
|
|
|
|
|
static bool mc_can_restart_foc(void) {
|
|
|
- bool can_start = (!mc_throttle_released() || (motor.epm_dir != EPM_Dir_None)) && (!mc_critical_can_not_run());
|
|
|
+ if (mc_critical_can_not_run()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bool can_start = (!mc_throttle_released() || (motor.epm_dir != EPM_Dir_None));
|
|
|
if (!foc_observer_is_encoder() && !foc_observer_sensorless_stable()){
|
|
|
return false;
|
|
|
}
|
|
|
- if ((motor.s_target_speed != MAX_S16 && motor.s_target_speed != 0) && (!mc_critical_can_not_run()) && motor.mode == CTRL_MODE_SPD) {
|
|
|
+ if ((motor.s_target_speed != MAX_S16 && motor.s_target_speed != 0) && motor.mode == CTRL_MODE_SPD) {
|
|
|
return true;
|
|
|
}
|
|
|
return can_start;
|