Kaynağa Gözat

每次开机FOC user 参数只使用nv初始化一次,后面等用户设置

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 yıl önce
ebeveyn
işleme
841cbb5e6b

+ 1 - 0
Applications/app/app.c

@@ -56,6 +56,7 @@ void fetch_jtag_cmd(void) {
 		//mc_current_sensor_calibrate((float)jtag_data/10.0f);
 		//mc_current_sensor_calibrate((float)jtag_data/10.0f);
 		jtag_cmd = 0;
 		jtag_cmd = 0;
 	}
 	}
+	jtag_cmd = 0;
 }
 }
 #else
 #else
 void fetch_jtag_cmd(void){
 void fetch_jtag_cmd(void){

+ 7 - 2
Applications/foc/commands.c

@@ -79,11 +79,16 @@ static void process_foc_command(foc_cmd_body_t *command) {
 			s16 speed = decode_s16(((u8 *)command->data));
 			s16 speed = decode_s16(((u8 *)command->data));
 			PMSM_FOC_SpeedLimit(speed);
 			PMSM_FOC_SpeedLimit(speed);
 		}
 		}
-		case Foc_Set_Current_Limit:
+		case Foc_Set_iDC_Limit:
 		{
 		{
 			s16 current = decode_s16(((u8 *)command->data));
 			s16 current = decode_s16(((u8 *)command->data));
 			PMSM_FOC_iBusLimit(current);
 			PMSM_FOC_iBusLimit(current);
-		}		
+		}
+		case Foc_Set_Phase_Current:
+		{
+			s16 curr = decode_s16(((u8 *)command->data));
+			PMSM_FOC_PhaseCurrLim((float)curr);
+		}
 		case Foc_Cali_Hall_Phase:
 		case Foc_Cali_Hall_Phase:
 		{
 		{
 			s16 vd = decode_s16((u8 *)command->data);
 			s16 vd = decode_s16((u8 *)command->data);

+ 2 - 1
Applications/foc/commands.h

@@ -7,11 +7,12 @@ typedef enum {
 	Foc_Start_Motor = 1, //foc_start_stop_t, ready, unread, 014d01
 	Foc_Start_Motor = 1, //foc_start_stop_t, ready, unread, 014d01
 	Foc_Cali_Hall_Phase, //calibrate hall phase, get the angle when motor running 0-360
 	Foc_Cali_Hall_Phase, //calibrate hall phase, get the angle when motor running 0-360
 	Foc_Cali_Hall_Offset,//calibrate hall offset from A phase 0x034d00
 	Foc_Cali_Hall_Offset,//calibrate hall offset from A phase 0x034d00
-	Foc_Set_Current_Limit,   //u32, set the limited current//mA
+	Foc_Set_iDC_Limit,   //u32, set the limited current//mA
 	Foc_Set_Speed_Limit,     //u32, set the limited speed//rpm
 	Foc_Set_Speed_Limit,     //u32, set the limited speed//rpm
 	Foc_Set_Speed_Target,    //u32, set the target speed, just for test
 	Foc_Set_Speed_Target,    //u32, set the target speed, just for test
 	Foc_Set_Cruise_Speed,    //u32, set the speed for curise riding
 	Foc_Set_Cruise_Speed,    //u32, set the speed for curise riding
 	Foc_Set_Cruise_Mode,
 	Foc_Set_Cruise_Mode,
+	Foc_Set_Phase_Current,
 	Foc_Conf_Pid,
 	Foc_Conf_Pid,
 	Foc_Hall_Phase_Cali_Result,
 	Foc_Hall_Phase_Cali_Result,
 	Foc_Hall_Offset_Cali_Result,
 	Foc_Hall_Offset_Cali_Result,

+ 30 - 12
Applications/foc/core/PMSM_FOC_Core.c

@@ -15,7 +15,7 @@
 #include "math/fir.h"
 #include "math/fir.h"
 PMSM_FOC_Ctrl _gFOC_Ctrl;
 PMSM_FOC_Ctrl _gFOC_Ctrl;
 static Fir_t phase1, phase2;
 static Fir_t phase1, phase2;
-
+static bool g_focinit = false;
 static __INLINE void RevPark(DQ_t *dq, float angle, AB_t *alpha_beta) {
 static __INLINE void RevPark(DQ_t *dq, float angle, AB_t *alpha_beta) {
 	float c,s;
 	float c,s;
 #if 0
 #if 0
@@ -157,6 +157,19 @@ static void PMSM_FOC_Conf_PID(void) {
 	_gFOC_Ctrl.pi_ctl_lock->DT = (1.0f/(float)SPD_CTRL_TS);
 	_gFOC_Ctrl.pi_ctl_lock->DT = (1.0f/(float)SPD_CTRL_TS);
 
 
 }
 }
+
+static void PMSM_FOC_UserInit(void) {
+	memset(&_gFOC_Ctrl.userLim, 0, sizeof(_gFOC_Ctrl.userLim));
+	_gFOC_Ctrl.userLim.s_iDCLim = nv_get_foc_params()->s_maxiDC;
+	_gFOC_Ctrl.userLim.s_motRPMLim = nv_get_foc_params()->s_maxRPM;//(MAX_SPEED);
+	_gFOC_Ctrl.userLim.s_torqueLim = nv_get_foc_params()->s_maxTorque;//MAX_TORQUE;
+	_gFOC_Ctrl.userLim.s_PhaseCurrLim = nv_get_foc_params()->s_PhaseCurrLim;
+	_gFOC_Ctrl.userLim.s_vDCMaxLim = nv_get_foc_params()->s_maxvDC;
+	_gFOC_Ctrl.userLim.s_vDCMinLim = _gFOC_Ctrl.userLim.s_vDCMaxLim / 3;
+	_gFOC_Ctrl.userLim.s_iDCeBrkLim = nv_get_foc_params()->s_maxBrkCurrent;
+	_gFOC_Ctrl.userLim.s_PhaseeVoleBrkLim = _gFOC_Ctrl.hwLim.s_PhaseVolMax - 20;
+}
+
 void PMSM_FOC_CoreInit(void) {
 void PMSM_FOC_CoreInit(void) {
 	Fir_init(&phase1);
 	Fir_init(&phase1);
 	Fir_init(&phase2);
 	Fir_init(&phase2);
@@ -172,23 +185,18 @@ void PMSM_FOC_CoreInit(void) {
 	
 	
 	memset(&_gFOC_Ctrl.in, 0, sizeof(_gFOC_Ctrl.in));
 	memset(&_gFOC_Ctrl.in, 0, sizeof(_gFOC_Ctrl.in));
 	memset(&_gFOC_Ctrl.out, 0, sizeof(_gFOC_Ctrl.out));
 	memset(&_gFOC_Ctrl.out, 0, sizeof(_gFOC_Ctrl.out));
-	memset(&_gFOC_Ctrl.userLim, 0, sizeof(_gFOC_Ctrl.userLim));
-
+	
 	_gFOC_Ctrl.hwLim.s_iDCMax = CONFIG_MAX_VBUS_CURRENT;
 	_gFOC_Ctrl.hwLim.s_iDCMax = CONFIG_MAX_VBUS_CURRENT;
 	_gFOC_Ctrl.hwLim.s_motRPMMax = CONFIG_MAX_MOT_RPM;
 	_gFOC_Ctrl.hwLim.s_motRPMMax = CONFIG_MAX_MOT_RPM;
 	_gFOC_Ctrl.hwLim.s_PhaseCurrMax = CONFIG_MAX_PHASE_CURR;
 	_gFOC_Ctrl.hwLim.s_PhaseCurrMax = CONFIG_MAX_PHASE_CURR;
 	_gFOC_Ctrl.hwLim.s_PhaseVolMax = CONFIG_MAX_PHASE_VOL;
 	_gFOC_Ctrl.hwLim.s_PhaseVolMax = CONFIG_MAX_PHASE_VOL;
 	_gFOC_Ctrl.hwLim.s_vDCMax      = CONFIG_MAX_VBUS_VOLTAGE;
 	_gFOC_Ctrl.hwLim.s_vDCMax      = CONFIG_MAX_VBUS_VOLTAGE;
 	_gFOC_Ctrl.hwLim.s_torqueMax  = CONFIG_MAX_TORQUE;
 	_gFOC_Ctrl.hwLim.s_torqueMax  = CONFIG_MAX_TORQUE;
-	_gFOC_Ctrl.userLim.s_iDCLim = nv_get_foc_params()->s_maxiDC;
-	_gFOC_Ctrl.userLim.s_motRPMLim = nv_get_foc_params()->s_maxRPM;//(MAX_SPEED);
-	_gFOC_Ctrl.userLim.s_torqueLim = nv_get_foc_params()->s_maxTorque;//MAX_TORQUE;
-	_gFOC_Ctrl.userLim.s_PhaseCurrLim = nv_get_foc_params()->s_PhaseCurrLim;
-	_gFOC_Ctrl.userLim.s_vDCMaxLim = nv_get_foc_params()->s_maxvDC;
-	_gFOC_Ctrl.userLim.s_vDCMinLim = _gFOC_Ctrl.userLim.s_vDCMaxLim / 3;
-	_gFOC_Ctrl.userLim.s_iDCeBrkLim = nv_get_foc_params()->s_maxBrkCurrent;
-	_gFOC_Ctrl.userLim.s_PhaseeVoleBrkLim = _gFOC_Ctrl.hwLim.s_PhaseVolMax - 20;
-	
+
+	if (!g_focinit) {
+		PMSM_FOC_UserInit();
+		g_focinit = false;
+	}
 	_gFOC_Ctrl.params.n_modulation = nv_get_foc_params()->n_modulation;//SVM_Modulation;
 	_gFOC_Ctrl.params.n_modulation = nv_get_foc_params()->n_modulation;//SVM_Modulation;
 	_gFOC_Ctrl.params.n_PhaseFilterCeof = nv_get_foc_params()->n_PhaseFilterCeof;//(0.2f);
 	_gFOC_Ctrl.params.n_PhaseFilterCeof = nv_get_foc_params()->n_PhaseFilterCeof;//(0.2f);
 	//_gFOC_Ctrl.params.n_TrqVelLimGain = nv_get_foc_params()->n_TrqVelLimGain;
 	//_gFOC_Ctrl.params.n_TrqVelLimGain = nv_get_foc_params()->n_TrqVelLimGain;
@@ -522,6 +530,16 @@ u8 PMSM_FOC_GetCtrlMode(void) {
 	return _gFOC_Ctrl.in.n_ctlMode;
 	return _gFOC_Ctrl.in.n_ctlMode;
 }
 }
 
 
+void PMSM_FOC_PhaseCurrLim(float lim) {
+	if (lim > _gFOC_Ctrl.hwLim.s_PhaseCurrMax) {
+		lim = _gFOC_Ctrl.hwLim.s_PhaseCurrMax;
+	}
+	_gFOC_Ctrl.userLim.s_PhaseCurrLim = lim;
+}
+
+float PMSM_FOC_GetPhaseCurrLim(void) {
+	return _gFOC_Ctrl.userLim.s_PhaseCurrLim;
+}
 
 
 void PMSM_FOC_SetOpenVdq(float vd, float vq) {
 void PMSM_FOC_SetOpenVdq(float vd, float vq) {
 	FOC_Set_vDqRamp(&_gFOC_Ctrl.vdq_ctl[0], vd);
 	FOC_Set_vDqRamp(&_gFOC_Ctrl.vdq_ctl[0], vd);

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

@@ -226,6 +226,8 @@ float PMSM_FOC_GeteBrkPhaseCurrent(void);
 void PMSM_FOC_SetCriticalError(u8 err) ;
 void PMSM_FOC_SetCriticalError(u8 err) ;
 void PMSM_FOC_ClrCriticalError(u8 err);
 void PMSM_FOC_ClrCriticalError(u8 err);
 u32 PMSM_FOC_GetCriticalError(void);
 u32 PMSM_FOC_GetCriticalError(void);
+void PMSM_FOC_PhaseCurrLim(float lim);
+float PMSM_FOC_GetPhaseCurrLim(void);
 
 
 #endif /* _PMSM_FOC_Core_H__ */
 #endif /* _PMSM_FOC_Core_H__ */
 
 

+ 1 - 1
Project/MC100.uvoptx

@@ -120,7 +120,7 @@
         <SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Number>0</Number>
           <Key>DLGUARM</Key>
           <Key>DLGUARM</Key>
-          <Name>?</Name>
+          <Name>窧H
:</Name>
         </SetRegEntry>
         </SetRegEntry>
         <SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Number>0</Number>