Просмотр исходного кода

通过温度突变检测温度传感器异常

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 лет назад
Родитель
Сommit
44afa733f3

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

@@ -70,6 +70,8 @@ typedef enum {
 	FOC_CRIT_Vol_HW_Err, //17
 	FOC_CRIT_PHASE_UNBalance_Err, /* 三相不平衡错误,比如相线螺丝松了 */
 	FOC_CRIT_THRO2_Err,
+	FOC_CRIT_MOT_TEMP_Sensor,
+	FOC_CRIT_MOS_TEMP_Sensor,
 	FOC_CRIT_Err_Max = 32,
 }FOC_CritiCal_Ebit_t;
 

+ 36 - 2
Applications/foc/limit.c

@@ -11,6 +11,8 @@ static limter_t mos_temp_lim[3];
 static limter_t vol_under_lim[1];
 static bool _inited = false;
 static bool _can_recovery = true;
+static s16 mot_temp, mos_temp;
+
 static void limiter_init(void) {
 	mc_limit_t *limiter = nv_get_limter();
 	for (int i = 0; i < TEMP_LIMITER_NUM; i++) {
@@ -27,6 +29,8 @@ static void limiter_init(void) {
 	vol_under_lim[0].exit_pointer = limiter->vbus.exit_pointer;
 	vol_under_lim[0].limit_value = limiter->vbus.limit_value;
 	//sys_debug("%d-%d-%d\n", vol_under_lim[0].enter_pointer, vol_under_lim[0].exit_pointer, vol_under_lim[0].limit_value);
+	mot_temp = sample_motor_temp();
+	mos_temp = sample_mos_temp();
 }
 
 static u16 _temp_limiter(s16 temp, limter_t *lim) {
@@ -90,10 +94,25 @@ static u16 _vol_limiter(s16 vol, limter_t *lim) {
 }
 
 static u16 _motor_limit(void) {
+	static int temp_sensor_err = 0;
+	static u16 lim_value  = HW_LIMIT_NONE;
 	s16 temp = get_motor_temp_raw();
+	if (ABS(temp - mot_temp) >= 20) {
+		if (temp_sensor_err < 20) {
+			temp_sensor_err++;
+		}else {
+			if (mc_set_critical_error(FOC_CRIT_MOT_TEMP_Sensor)) {
+				mc_crit_err_add(FOC_CRIT_MOT_TEMP_Sensor, temp, mot_temp);
+			}
+		}
+		return lim_value; //温度传感器异常,返回上次的限流
+	}else {
+		mot_temp = temp;
+		temp_sensor_err = 0;
+	}
 	for(int i = 0; i < ARRAY_SIZE(motor_temp_lim); i++) {
 		limter_t *lim = motor_temp_lim + i;
-		u16 lim_value = _temp_limiter(temp, lim);
+		lim_value = _temp_limiter(temp, lim);
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
 				if (mc_set_critical_error(FOC_CRIT_MOTOR_TEMP_Lim)) {
@@ -132,10 +151,25 @@ static u16 _motor_limit(void) {
 }
 
 static u16 _mos_limit(void) {
+	static int temp_sensor_err = 0;
+	static u16 lim_value  = HW_LIMIT_NONE;
 	s16 temp = get_mos_temp_raw();
+	if (ABS(temp - mos_temp) >= 20) {
+		if (temp_sensor_err < 20) {
+			temp_sensor_err++;
+		}else {
+			if (mc_set_critical_error(FOC_CRIT_MOS_TEMP_Sensor)) {
+				mc_crit_err_add(FOC_CRIT_MOS_TEMP_Sensor, temp, mos_temp);
+			}
+		}
+		return lim_value; //温度传感器异常,返回上次的限流
+	}else {
+		mos_temp = temp;
+		temp_sensor_err = 0;
+	}
 	for(int i = 0; i < ARRAY_SIZE(mos_temp_lim); i++) {
 		limter_t *lim = mos_temp_lim + i;
-		u16 lim_value = _temp_limiter(temp, lim);
+		lim_value = _temp_limiter(temp, lim);
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
 				if (mc_set_critical_error(FOC_CRIT_MOS_TEMP_Lim)) {

+ 8 - 2
Applications/foc/samples.c

@@ -274,7 +274,7 @@ void sample_uvw_phase(void) {
 #endif
 }
 
-void sample_motor_temp(void) {
+s16 sample_motor_temp(void) {
 #ifdef CONFIG_BOARD_MCXXX
 	u16 adc = adc_get_motor_temp();
 	u32 r = (u32)MOTOR_TEMP_R(adc);
@@ -283,10 +283,13 @@ void sample_motor_temp(void) {
 	}
 	motor_temp.value = ntc_get_motor_temp(r);
 	LowPass_Filter(motor_temp.filted_value, motor_temp.value, motor_temp.lowpass);
+	return (s16)motor_temp.value;
+#else
+	return 0;
 #endif
 }
 
-void sample_mos_temp(void) {
+s16 sample_mos_temp(void) {
 #ifdef CONFIG_BOARD_MCXXX
 	u16 adc = adc_get_mos_temp();
 	u32 r = (u32)MOS_TEMP_R(adc);
@@ -295,6 +298,9 @@ void sample_mos_temp(void) {
 	}
 	mos_temp.value = ntc_get_mos_temp(r);
 	LowPass_Filter(mos_temp.filted_value, mos_temp.value, mos_temp.lowpass);
+	return (s16)mos_temp.value;
+#else
+	return 0;
 #endif
 }
 

+ 2 - 2
Applications/foc/samples.h

@@ -11,8 +11,8 @@ void sample_uvw_phase(void);
 void sample_vbus(void);
 void sample_ibus(void);
 void sample_throttle(void);
-void sample_motor_temp(void);
-void sample_mos_temp(void);
+s16 sample_motor_temp(void);
+s16 sample_mos_temp(void);
 void sample_vref(void);
 s16 get_motor_temp_raw(void);
 s16 get_mos_temp_raw(void);