Procházet zdrojové kódy

timer brk中断中记录当前的重要数据,给诊断使用

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui před 3 roky
rodič
revize
368db640ce

+ 3 - 3
Applications/foc/commands.c

@@ -254,10 +254,10 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		}
 		case Foc_Set_iDC_Limit:
 		{
-			u8 current = decode_u8(((u8 *)command->data));
+			u16 current = decode_u16(((u8 *)command->data));
 			mc_set_idc_limit((float)current);
-			encode_u8(response + 3, (u8)PMSM_FOC_GetDCCurrLimit());
-			len += 1;
+			encode_u16(response + 3, (u16)PMSM_FOC_GetDCCurrLimit());
+			len += 2;
 			break;
 		}
 		case Foc_Set_Phase_CurrLim:

+ 17 - 6
Applications/foc/motor/motor.c

@@ -47,6 +47,7 @@ static motor_t motor = {
 	.b_is96Mode = false,
 	.mode = CTRL_MODE_OPEN,
 };
+static motor_err_t mc_error;
 
 static void MC_Check_MosVbusThrottle(void) {
 	int count = 1000;
@@ -916,7 +917,6 @@ static void _pwm_brake_prot_timer_handler(shark_timer_t *t){
 	pwm_brake_enable(true);
 	sys_debug("MC protect error\n");
 }
-static float err_vbus, err_id,err_iq, ctl_mode;
 
 void MC_Protect_IRQHandler(void){
 	pwm_brake_enable(false);
@@ -924,10 +924,21 @@ void MC_Protect_IRQHandler(void){
 	if (!motor.b_start) {
 		return;
 	}
-	err_vbus = get_vbus_float();
-	err_id = PMSM_FOC_Get()->idq_ctl[0].s_Cp;
-	err_iq = PMSM_FOC_Get()->idq_ctl[1].s_Cp;
-	ctl_mode = PMSM_FOC_Get()->out.n_RunMode;
+	mc_error.vbus = (s16)get_vbus_float(); 
+	mc_error.ibus = (s16)get_vbus_current();
+	mc_error.id_ref = (s16)PMSM_FOC_Get()->idq_ctl[0].s_Cp;
+	mc_error.iq_ref = (s16)PMSM_FOC_Get()->idq_ctl[1].s_Cp;
+	mc_error.run_mode = PMSM_FOC_Get()->out.n_RunMode;
+	mc_error.id = (s16)PMSM_FOC_Get()->out.s_RealIdq.d;
+	mc_error.iq = (s16)PMSM_FOC_Get()->out.s_RealIdq.q;
+	mc_error.vd = (s16)PMSM_FOC_Get()->out.s_OutVdq.d;
+	mc_error.vq = (s16)PMSM_FOC_Get()->out.s_OutVdq.q;
+	mc_error.rpm = (s16)motor_encoder_get_speed();
+	mc_error.torque_ref = (s16)PMSM_FOC_Get()->in.s_targetTorque;
+	mc_error.b_smo_running = !foc_observer_is_encoder();
+	mc_error.mos_temp = get_mos_temp();
+	mc_error.mot_temp = get_motor_temp();
+
 	mc_set_critical_error(FOC_CRIT_Phase_Err);
 	_mc_internal_init(CTRL_MODE_OPEN, false);
 	adc_stop_convert();
@@ -937,7 +948,7 @@ void MC_Protect_IRQHandler(void){
 }
 
 void motor_debug(void) {
-	sys_debug("err: %f, %f, %f, %d\n", err_vbus, err_id, err_iq, ctl_mode);
+	sys_debug("err: %f, %f, %f, %d\n", mc_error.vbus, mc_error.id_ref, mc_error.iq_ref, mc_error.run_mode);
 }
 
 void TIMER_UP_IRQHandler(void){

+ 17 - 0
Applications/foc/motor/motor.h

@@ -46,6 +46,23 @@ typedef struct {
 	fan_t  fan[2];
 }motor_t;
 
+typedef struct {
+	s16 vbus;
+	s16 ibus;
+	s16 id;
+	s16 iq;
+	s16 vd;
+	s16 vq;
+	s16 id_ref;
+	s16 iq_ref;
+	u8    run_mode;
+	s16 torque_ref;
+	s16 rpm;
+	bool  b_smo_running;
+	s16    mos_temp;
+	s16    mot_temp;
+}motor_err_t;
+
 motor_t * mc_params(void);
 void mc_init(void);
 bool mc_start(u8 mode);