Bladeren bron

相电流波形记录8000个点,然后输出给示波器,确保波形数据详细

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 jaren geleden
bovenliggende
commit
4fc1018800

+ 1 - 3
Applications/app/app.c

@@ -183,7 +183,7 @@ static u32 _app_plot_task(void * args) {
 	}else if (plot_type == 5) {
 		can_plot2((s16)PMSM_FOC_Get()->idq_ctl[0].s_Cp, (s16)PMSM_FOC_Get()->idq_ctl[1].s_Cp);
 	}else if (plot_type == 6) {
-		can_plot2((s16)(PMSM_FOC_Get()->in.s_iABC[0]), (s16)(PMSM_FOC_Get()->in.s_iABC[1]));
+		//can_plot2((s16)(PMSM_FOC_Get()->in.s_iABC[0]), (s16)(PMSM_FOC_Get()->in.s_iABC[1]));
 	}else if (plot_type == 7) {
 		#ifdef CONFIG_DQ_STEP_RESPONSE
 		can_plot2((s16)(target_d*10.0f), (s16)(PMSM_FOC_Get()->out.s_RealIdq.d * 10.0f));
@@ -193,8 +193,6 @@ static u32 _app_plot_task(void * args) {
 		can_plot2((s16)(target_q*10.0f), (s16)(PMSM_FOC_Get()->out.s_RealIdq.q * 10.0f));
 		#endif
 	}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_air(), (s16)F_get_accl(), (s16)F_get_Te());
 	}
 	

+ 7 - 0
Applications/foc/commands.c

@@ -453,6 +453,13 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		case Foc_Set_Plot_Type:
 		{
 			plot_type = (int)decode_u8((u8 *)command->data);
+		#if (CONFIG_ENABLE_IAB_REC==1)
+			if (plot_type == 6) {
+				mc_start_current_rec(true);
+			}else if (plot_type == 0) {
+				mc_start_current_rec(false);
+			}
+		#endif
 			sys_debug("plot type %d\n", plot_type);
 			break;
 		}

+ 3 - 0
Applications/foc/foc_config.h

@@ -68,6 +68,9 @@
 #define CONFIG_TCS_ENABLE         1
 
 #define CONFIG_MAX_NEG_TORQUE 0.0F
+
+#define CONFIG_ENABLE_IAB_REC 1   // for phase current debug
+
 #ifdef CONFIG_SPEED_LADRC
 	#define CONFIG_LADRC_Wo  200.0F
 	#define CONFIG_LADRC_Wcv 5.0F

+ 43 - 2
Applications/foc/motor/motor.c

@@ -1030,7 +1030,13 @@ void TIMER_UP_IRQHandler(void){
 measure_time_t g_meas_foc = {.exec_max_time = 25, .intval_max_time = 62,  .intval_low_err = 0, .intval_hi_err = 0, .first = true,};
 #define TIME_MEATURE_START() time_measure_start(&g_meas_foc)
 #define TIME_MEATURE_END() time_measure_end(&g_meas_foc)
-
+#if (CONFIG_ENABLE_IAB_REC==1)
+#define CONFIG_IAB_REC_COUNT 8000
+static s16 ia[CONFIG_IAB_REC_COUNT], ib[CONFIG_IAB_REC_COUNT];
+static int iab_w_count = 0, iab_r_count = 0;
+static bool b_iab_rec = false;
+extern void can_plot2(s16 v1, s16 v2);
+#endif
 /*ADC 电流采集中断,调用FOC的核心处理函数*/
 void ADC_IRQHandler(void) {
 	if (phase_current_offset()) {//check if is adc offset checked
@@ -1043,6 +1049,15 @@ void ADC_IRQHandler(void) {
 	}
 	TIME_MEATURE_START();
 
+#if (CONFIG_ENABLE_IAB_REC==1)
+	if (b_iab_rec && (iab_w_count < CONFIG_IAB_REC_COUNT)) {
+		float iabc[3];
+		phase_current_get(iabc);
+		ia[iab_w_count] = (s16)iabc[0];
+		ib[iab_w_count] = (s16)iabc[1];
+		iab_w_count ++;
+	}
+#endif
 	motor_vbus_crit_low((s16)sample_vbus_raw()); //need fast detect vbus very low, to stop the motor
 
 	if (!PMSM_FOC_Schedule()) {/* FOC 角度错误,立即停机 */
@@ -1069,7 +1084,33 @@ void ADC_IRQHandler(void) {
 	TIME_MEATURE_END();
 }
 
-
+#if (CONFIG_ENABLE_IAB_REC==1)
+static void _iab_plot_timer_handler(shark_timer_t *t) {
+	if (!b_iab_rec) {
+		return;
+	}
+	if (iab_r_count < iab_w_count) {
+		can_plot2(ia[iab_r_count], ib[iab_r_count]);
+		iab_r_count ++;
+		shark_timer_post(t, 10);
+	}
+}
+static shark_timer_t _iab_plot_timer = TIMER_INIT(_iab_plot_timer, _iab_plot_timer_handler);
+void mc_start_current_rec(bool rec) {
+	if (b_iab_rec == rec) {
+		return;
+	}
+	if (!rec) {
+		b_iab_rec = false;
+		shark_timer_cancel(&_iab_plot_timer);
+		return;
+	}
+	iab_w_count = 0;
+	iab_r_count = 0;
+	b_iab_rec = true;
+	shark_timer_post(&_iab_plot_timer, 100);
+}
+#endif
 static bool mc_run_stall_process(u8 run_mode) {
 	if ((run_mode == CTRL_MODE_TRQ || run_mode == CTRL_MODE_SPD) && !PMSM_FOC_AutoHoldding()) {
 		//堵转判断

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

@@ -106,6 +106,7 @@ s16 mc_get_ebrk_torque(void);
 u16 mc_get_ebrk_time(void);
 bool mc_critical_err_is_set(u8 err);
 bool mc_hwbrk_can_shutpower(void);
+void mc_start_current_rec(bool rec);
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL