Explorar o código

标定高温,过流保护

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=3) %!d(string=hai) anos
pai
achega
641a6aed66
Modificáronse 3 ficheiros con 58 adicións e 40 borrados
  1. 11 10
      Applications/app/app.c
  2. 13 9
      Applications/foc/limit.c
  3. 34 21
      Applications/foc/motor/motor.c

+ 11 - 10
Applications/app/app.c

@@ -126,22 +126,23 @@ static u32 _app_report_task(void *p) {
 	can_report_phase_current(0x45);
 	if (++loop % 10 == 0) {
 		//sys_debug("rst 0x%x\n", get_mcu_reset_source());
-		sys_debug("Slow: %d - %d\n", g_meas_MCTask.intval_time, g_meas_MCTask.exec_time);
-		sys_debug("Fast: %d - %d, err: %d-%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, g_meas_foc.exec_max_error_time);
+		//sys_debug("Slow: %d - %d\n", g_meas_MCTask.intval_time, g_meas_MCTask.exec_time);
+		//sys_debug("Fast: %d - %d, err: %d-%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, g_meas_foc.exec_max_error_time);
 		sys_debug("FOC time err %d %d\n", g_meas_foc.intval_time_h_error, g_meas_foc.intval_time_l_error);
-		sys_debug("acc vol %d, bid %d\n", get_acc_vol(), gpio_board_id());
-		sys_debug("throttle %f\n", get_throttle_float());
-		sys_debug("ADC Vref %f, %f\n", get_adc_vref(), adc_5vref_compesion());
+		//sys_debug("acc vol %d, bid %d\n", get_acc_vol(), gpio_board_id());
+		//sys_debug("throttle %f\n", get_throttle_float());
+		//sys_debug("ADC Vref %f, %f\n", get_adc_vref(), adc_5vref_compesion());
 		//sys_debug("dead time %d\n", get_deadtime());
-		sys_debug("Sensorless err %d\n", foc_observer_enc_errcount());
+		//sys_debug("Sensorless err %d\n", foc_observer_enc_errcount());
 		//thro_torque_log();
-		sys_debug("_>%f, %f, %f\n", ladrc_observer_get()->ld, ladrc_observer_get()->lq, ladrc_observer_get()->poles);
+		//sys_debug("_>%f, %f, %f\n", ladrc_observer_get()->ld, ladrc_observer_get()->lq, ladrc_observer_get()->poles);
 		encoder_log();
 		//sample_log();
-		PMSM_FOC_LogDebug();
-		F_debug();
+		//PMSM_FOC_LogDebug();
+		//F_debug();
 		//eCtrl_debug_log();
 		//err_code_log();
+		sys_debug("limit %f %f\n", PMSM_FOC_Get()->rtLim.torqueLimRamp.target, PMSM_FOC_Get()->rtLim.torqueLimRamp.interpolation);
 	}
 	return 200;
 }
@@ -179,7 +180,7 @@ static u32 _app_plot_task(void * args) {
 	}else if (plot_type == 9) {
 		can_plot3((s16)PMSM_FOC_Get()->out.s_FilteriDC, (s16)PMSM_FOC_Get()->out.s_CalciDC, (s16)PMSM_FOC_Get()->out.s_CalciDC2);
 	}else if (plot_type == 10) {
-		can_plot3((s16)F_get_MotAccl() * 100, (s16)PMSM_FOC_GetSpeed(), (s16)F_get_Te());
+		can_plot3((s16)F_get_air(), (s16)F_get_accl(), (s16)F_get_Te());
 	}
 	
 	return 20;

+ 13 - 9
Applications/foc/limit.c

@@ -17,16 +17,16 @@ static void limiter_init(void) {
 		motor_temp_lim[i].enter_pointer = limiter->motor[i].enter_pointer;
 		motor_temp_lim[i].exit_pointer = limiter->motor[i].exit_pointer;
 		motor_temp_lim[i].limit_value = limiter->motor[i].limit_value;
-		//sys_debug("%d-%d-%d\n", motor_temp_lim[i].enter_pointer, motor_temp_lim[i].exit_pointer, motor_temp_lim[i].limit_value);
+		sys_debug("%d-%d-%d\n", motor_temp_lim[i].enter_pointer, motor_temp_lim[i].exit_pointer, motor_temp_lim[i].limit_value);
 		mos_temp_lim[i].enter_pointer = limiter->mos[i].enter_pointer;
 		mos_temp_lim[i].exit_pointer = limiter->mos[i].exit_pointer;
 		mos_temp_lim[i].limit_value = limiter->mos[i].limit_value;
-		//sys_debug("%d-%d-%d\n", mos_temp_lim[i].enter_pointer, mos_temp_lim[i].exit_pointer, mos_temp_lim[i].limit_value);
+		sys_debug("%d-%d-%d\n", mos_temp_lim[i].enter_pointer, mos_temp_lim[i].exit_pointer, mos_temp_lim[i].limit_value);
 	}
 	vol_under_lim[0].enter_pointer = limiter->vbus.enter_pointer;
 	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);
+	//sys_debug("%d-%d-%d\n", vol_under_lim[0].enter_pointer, vol_under_lim[0].exit_pointer, vol_under_lim[0].limit_value);
 }
 
 static u16 _temp_limiter(s16 temp, limter_t *lim) {
@@ -37,7 +37,7 @@ static u16 _temp_limiter(s16 temp, limter_t *lim) {
 		}
 		if (lim->ticks == 0) {
 			lim->ticks = get_tick_ms();
-		}else if (get_delta_ms(lim->ticks) >= 5000){
+		}else if (get_delta_ms(lim->ticks) >= 500){
 			lim->is_limit = true;
 			lim->ticks = 0;
 			return lim->limit_value;
@@ -50,7 +50,7 @@ static u16 _temp_limiter(s16 temp, limter_t *lim) {
 		}
 		if (lim->ticks == 0) {
 			lim->ticks = get_tick_ms();
-		}else if (get_delta_ms(lim->ticks) >= 5000) {
+		}else if (get_delta_ms(lim->ticks) >= 500) {
 			lim->is_limit = false;
 			lim->ticks = 0;
 			return HW_LIMIT_NONE;
@@ -67,7 +67,7 @@ static u16 _vol_limiter(s16 vol, limter_t *lim) {
 		}
 		if (lim->ticks == 0) {
 			lim->ticks = get_tick_ms();
-		}else if (get_delta_ms(lim->ticks) >= 1000){
+		}else if (get_delta_ms(lim->ticks) >= 100){
 			lim->is_limit = true;
 			lim->ticks = 0;
 			return lim->limit_value;
@@ -80,7 +80,7 @@ static u16 _vol_limiter(s16 vol, limter_t *lim) {
 		}
 		if (lim->ticks == 0) {
 			lim->ticks = get_tick_ms();
-		}else if (get_delta_ms(lim->ticks) >= 1000) {
+		}else if (get_delta_ms(lim->ticks) >= 100) {
 			lim->is_limit = false;
 			lim->ticks = 0;
 			return HW_LIMIT_NONE;
@@ -97,12 +97,14 @@ static u16 _motor_limit(void) {
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
 				mc_set_critical_error(FOC_CRIT_MOTOR_TEMP_Err);
+			}else {
+				mc_clr_critical_error(FOC_CRIT_MOTOR_TEMP_Err);
 			}
 			err_add_record(FOC_CRIT_MOTOR_TEMP_Err, temp);
 			return lim_value;
 		}
 	}
-	mc_clr_critical_error(FOC_CRIT_MOTOR_TEMP_Err);
+	
 	return HW_LIMIT_NONE;
 }
 
@@ -114,12 +116,14 @@ static u16 _mos_limit(void) {
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
 				mc_set_critical_error(FOC_CRIT_MOS_TEMP_Err);
+			}else {
+				mc_clr_critical_error(FOC_CRIT_MOS_TEMP_Err);
 			}
 			err_add_record(FOC_CRIT_MOS_TEMP_Err, temp);
 			return lim_value;
 		}
 	}
-	mc_clr_critical_error(FOC_CRIT_MOS_TEMP_Err);
+	
 	return HW_LIMIT_NONE;
 }
 

+ 34 - 21
Applications/foc/motor/motor.c

@@ -227,8 +227,9 @@ mc_gear_t *mc_get_gear_config(void) {
 	return mc_get_gear_config_by_gear(motor.n_gear);
 }
 
-bool mc_critical_not_running(void) {
-	u32 err = motor.n_CritiCalErrMask & (FOC_CRIT_IDC_OV | FOC_CRIT_MOTOR_TEMP_Err | FOC_CRIT_MOS_TEMP_Err);
+bool mc_critical_can_not_run(void) {
+	u32 mask = FOC_Cri_Err_Mask(FOC_CRIT_IDC_OV) | FOC_Cri_Err_Mask(FOC_CRIT_MOTOR_TEMP_Err) | FOC_Cri_Err_Mask(FOC_CRIT_MOS_TEMP_Err);
+	u32 err = motor.n_CritiCalErrMask & mask;
 	return (err != 0);
 }
 
@@ -414,6 +415,9 @@ bool mc_set_foc_mode(u8 mode) {
 	if (!motor.b_start) {
 		return false;
 	}
+	if (mc_critical_can_not_run()) {
+		return false;
+	}
 	if ((mode == CTRL_MODE_OPEN) && (ABS(PMSM_FOC_GetSpeed()) > CONFIG_ZERO_SPEED_RPM)) {
 		PMSM_FOC_SetErrCode(FOC_NotAllowed);
 		return false;
@@ -1013,9 +1017,12 @@ void ADC_IRQHandler(void) {
 
 #ifndef CONFIG_DQ_STEP_RESPONSE
 static bool mc_can_stop_foc(void) {
-	if (mc_critical_not_running()) {
+	if (mc_critical_can_not_run()) {
 		return true;
 	}
+	if (motor.mode == CTRL_MODE_CURRENT) {
+		return false;
+	}
 	if (mc_throttle_released() && PMSM_FOC_GetSpeed() == 0.0f) {
 		if (!PMSM_FOC_AutoHoldding() && motor.epm_dir == EPM_Dir_None) {
 			return true;
@@ -1166,6 +1173,27 @@ static void mc_process_curise(void) {
 	}
 }
 #endif
+
+static void mc_motor_runstop(void) {
+	u32 mask;
+	if (mc_can_stop_foc()) {
+		if (PMSM_FOC_Is_Start()) {
+			mask = cpu_enter_critical();
+			PMSM_FOC_Stop();
+			pwm_disable_channel();
+			cpu_exit_critical(mask);
+		}
+	}
+	if (mc_can_restart_foc()) {
+		mask = cpu_enter_critical();
+		PMSM_FOC_Start(motor.mode);
+		mc_gear_vmode_changed();
+		thro_torque_reset();
+		pwm_enable_channel();
+		cpu_exit_critical(mask);
+	}
+}
+
 /*FOC 的部分处理,比如速度环,状态机,转把采集等*/
 measure_time_t g_meas_MCTask;
 #define mc_TaskStart time_measure_start(&g_meas_MCTask)
@@ -1208,9 +1236,10 @@ void Sched_MC_mTask(void) {
 	}
 
 	/* 堵转处理 */
-	if (mc_run_stall_process(runMode) || (runMode == CTRL_MODE_CURRENT)) {
+	if (mc_run_stall_process(runMode) || (motor.mode == CTRL_MODE_CURRENT)) {
 		eCtrl_Running();
 		PMSM_FOC_Slow_Task();
+		mc_motor_runstop();
 		mc_TaskEnd;
 		return;
 	}
@@ -1219,23 +1248,7 @@ void Sched_MC_mTask(void) {
 #ifndef CONFIG_DQ_STEP_RESPONSE
 		mc_autohold_process();
 		if (motor.mode != CTRL_MODE_OPEN) {
-			u32 mask;
-			if (mc_can_stop_foc()) {
-				if (PMSM_FOC_Is_Start()) {
-					mask = cpu_enter_critical();
-					PMSM_FOC_Stop();
-					pwm_disable_channel();
-					cpu_exit_critical(mask);
-				}
-			}
-			if (mc_can_restart_foc()) {
-				mask = cpu_enter_critical();
-				PMSM_FOC_Start(motor.mode);
-				mc_gear_vmode_changed();
-				thro_torque_reset();
-				pwm_enable_channel();
-				cpu_exit_critical(mask);
-			}
+			mc_motor_runstop();
 		}
 		if (runMode != CTRL_MODE_OPEN) {
 			eCtrl_Running();