Ver código fonte

风扇错误检测

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 anos atrás
pai
commit
d5b331b0dc

+ 1 - 1
Applications/app/app.c

@@ -101,7 +101,7 @@ static u32 _app_report_task(void *p) {
 		sys_debug("Fast: %d - %d, err: %d-%d\n", g_meas_foc.intval_time, g_meas_foc.exec_time, g_meas_foc.intval_hi_err, g_meas_foc.intval_low_err);
 		sys_debug("acc vol %d, mos2 %d\n", get_acc_vol(), get_mos_temp2());
 		sys_debug("throttle %f\n", get_throttle_float());
-		sys_debug("fan rpm %d, %d\n", mc_params()->fan[0].det_ts, mc_params()->fan[1].det_ts);
+		sys_debug("fan rpm %d, %d\n", mc_params()->fan[0].rpm, mc_params()->fan[1].rpm);
 		//encoder_log();
 		//err_code_log();
 	}

+ 2 - 0
Applications/foc/core/PMSM_FOC_Core.h

@@ -60,6 +60,8 @@ typedef enum {
 	FOC_CRIT_Phase_Conn_Err,
 	FOC_CRIT_MOTOR_TEMP_Err,
 	FOC_CRIT_MOS_TEMP_Err,
+	FOC_CRIT_Fan1_Err,
+	FOC_CRIT_Fan2_Err,
 	FOC_CRIT_Err_Max = 32,	
 }FOC_CritiCal_Ebit_t;
 

+ 42 - 1
Applications/foc/motor/motor.c

@@ -28,6 +28,9 @@ static void _pwm_brake_prot_timer_handler(shark_timer_t *);
 static shark_timer_t _brake_prot_timer = TIMER_INIT(_brake_prot_timer, _pwm_brake_prot_timer_handler);
 static void _autohold_beep_timer_handler(shark_timer_t *);
 static shark_timer_t _autohold_beep_timer = TIMER_INIT(_autohold_beep_timer, _autohold_beep_timer_handler);
+static void _fan_det_timer_handler(shark_timer_t *);
+static shark_timer_t _fan_det_timer1 = TIMER_INIT(_fan_det_timer1, _fan_det_timer_handler);
+static shark_timer_t _fan_det_timer2 = TIMER_INIT(_fan_det_timer2, _fan_det_timer_handler);
 
 
 static motor_t motor = {
@@ -74,6 +77,18 @@ static u32 _self_check_task(void *p) {
 			mc_lock_motor(false);
 		}
 	}
+	if (fan_pwm_is_running()) {
+		if ((get_delta_ms(motor.fan[0].start_ts) >= 5000) && (motor.fan[0].rpm == 0)) {
+			mc_set_critical_error(FOC_CRIT_Fan1_Err);
+		}else if (motor.fan[0].rpm > 0) {
+			mc_clr_critical_error(FOC_CRIT_Fan1_Err);
+		}
+		if ((get_delta_ms(motor.fan[1].start_ts) >= 5000) && (motor.fan[1].rpm == 0)) {
+			mc_set_critical_error(FOC_CRIT_Fan2_Err);
+		}else if (motor.fan[1].rpm > 0) {
+			mc_clr_critical_error(FOC_CRIT_Fan2_Err);
+		}
+	}
 	return 5;
 }
 
@@ -136,6 +151,12 @@ void mc_need_update(void) {
 	motor.b_updated = true;
 }
 
+bool mc_unsafe_critical_error(void) {
+	u32 err = motor.n_CritiCalErrMask & (~FOC_CRIT_Fan1_Err);
+	err = err & (~FOC_CRIT_Fan2_Err);
+	return (err != 0);
+}
+
 bool mc_start(u8 mode) {
 	if (motor.b_start) {
 		return true;
@@ -151,7 +172,7 @@ bool mc_start(u8 mode) {
 	}
 	MC_Check_MosVbusThrottle();
 
-	if (mc_get_critical_error() != 0) {
+	if (mc_unsafe_critical_error() != 0) {
 		PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
 		return false;
 	}
@@ -352,6 +373,11 @@ void mc_set_fan_duty(u8 duty) {
 	if (!fan_pwm_is_running() && duty > 0) {
 		motor.fan[0].start_ts = get_tick_ms();
 		motor.fan[1].start_ts = get_tick_ms();
+		shark_timer_post(&_fan_det_timer1, 5000);
+		shark_timer_post(&_fan_det_timer2, 5000);
+	}else if (duty == 0) {
+		shark_timer_cancel(&_fan_det_timer1);
+		shark_timer_cancel(&_fan_det_timer2);
 	}
 	fan_set_duty(duty);
 }
@@ -603,6 +629,16 @@ static bool mc_is_hwbrake(void) {
 	return false;
 }
 
+static void _fan_det_timer_handler(shark_timer_t *t) {
+	if (t == &_fan_det_timer1) {
+		motor.fan[0].rpm = 0;
+		motor.fan[0].det_ts = 0;
+	}else {
+		motor.fan[1].rpm = 0;
+		motor.fan[1].det_ts = 0;
+	}
+}
+
 void Fan_IRQHandler(int idx) {
 	fan_t *fan = motor.fan + idx;
 	u32 pre_ts = fan->det_ts;
@@ -611,6 +647,11 @@ void Fan_IRQHandler(int idx) {
 	float rpm = 60.0f * 1000 / (float)delta_ts;
 
 	LowPass_Filter(fan->rpm, rpm, 0.1f);
+	if (idx == 0) {
+		shark_timer_post(&_fan_det_timer1, 5000);
+	}else {
+		shark_timer_post(&_fan_det_timer2, 5000);
+	}
 }
 
 void MC_Brake_IRQHandler(void) {