|
|
@@ -178,10 +178,12 @@ static void PMSM_FOC_UserInit(void) {
|
|
|
|
|
|
gFoc_Ctrl.protLim.s_iDCLim = gFoc_Ctrl.userLim.s_iDCLim;
|
|
|
gFoc_Ctrl.protLim.s_PhaseCurrLim = gFoc_Ctrl.userLim.s_PhaseCurrLim;
|
|
|
+}
|
|
|
|
|
|
- eRamp_init_target(&gFoc_Ctrl.userLim.rpmLimRamp, gFoc_Ctrl.userLim.s_motRPMLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
- eRamp_init_target(&gFoc_Ctrl.userLim.phaseCurrLimRamp, gFoc_Ctrl.userLim.s_PhaseCurrLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
- eRamp_init_target(&gFoc_Ctrl.userLim.DCCurrLimRamp, gFoc_Ctrl.userLim.s_iDCLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
+void PMSM_FOC_RT_LimInit(void) {
|
|
|
+ eRamp_init_target(&gFoc_Ctrl.rtLim.rpmLimRamp, gFoc_Ctrl.userLim.s_motRPMLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
+ eRamp_init_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, gFoc_Ctrl.userLim.s_PhaseCurrLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
+ eRamp_init_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, gFoc_Ctrl.userLim.s_iDCLim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_CoreInit(void) {
|
|
|
@@ -209,6 +211,7 @@ void PMSM_FOC_CoreInit(void) {
|
|
|
gFoc_Ctrl.hwLim.s_FWDCurrMax = CONFIG_MAX_FW_D_CURR;
|
|
|
if (!g_focinit) {
|
|
|
PMSM_FOC_UserInit();
|
|
|
+ PMSM_FOC_RT_LimInit();
|
|
|
shark_task_create(PMSM_FOC_Debug_Task, NULL);
|
|
|
g_focinit = true;
|
|
|
}
|
|
|
@@ -436,7 +439,7 @@ u8 PMSM_FOC_CtrlMode(void) {
|
|
|
static __INLINE float PMSM_FOC_Limit_iDC(float maxTrq) {
|
|
|
#if 1
|
|
|
PI_Ctrl_Power.max = maxTrq;
|
|
|
- float errRef = eRamp_get_intepolation(&gFoc_Ctrl.userLim.DCCurrLimRamp) - gFoc_Ctrl.out.s_FilteriDC;
|
|
|
+ float errRef = eRamp_get_intepolation(&gFoc_Ctrl.rtLim.DCCurrLimRamp) - gFoc_Ctrl.out.s_FilteriDC;
|
|
|
return PI_Controller_run(gFoc_Ctrl.pi_power, errRef);
|
|
|
#else
|
|
|
return maxTrq;
|
|
|
@@ -486,8 +489,8 @@ void PMSM_FOC_idqCalc(void) {
|
|
|
}
|
|
|
}
|
|
|
}else if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) {
|
|
|
- float refTorque = min(eCtrl_get_FinalTorque(), eRamp_get_intepolation(&gFoc_Ctrl.userLim.phaseCurrLimRamp));
|
|
|
- if (refTorque > 0) {
|
|
|
+ float refTorque = min(eCtrl_get_FinalTorque(), eRamp_get_intepolation(&gFoc_Ctrl.rtLim.phaseCurrLimRamp));
|
|
|
+ if (refTorque >= 0) {
|
|
|
gFoc_Ctrl.pi_torque->max = refTorque;
|
|
|
gFoc_Ctrl.pi_torque->min = -gFoc_Ctrl.userLim.s_PhaseCurreBrkLim;
|
|
|
}else {
|
|
|
@@ -498,7 +501,7 @@ void PMSM_FOC_idqCalc(void) {
|
|
|
gFoc_Ctrl.pi_torque->max = 0;
|
|
|
gFoc_Ctrl.pi_torque->min = 0; //防止倒转
|
|
|
}
|
|
|
- float errRef = eRamp_get_intepolation(&gFoc_Ctrl.userLim.rpmLimRamp) - gFoc_Ctrl.in.s_motRPM;
|
|
|
+ float errRef = eRamp_get_intepolation(&gFoc_Ctrl.rtLim.rpmLimRamp) - gFoc_Ctrl.in.s_motRPM;
|
|
|
float maxTrq = PI_Controller_RunSat(gFoc_Ctrl.pi_torque, errRef);
|
|
|
gFoc_Ctrl.in.s_targetTorque = PMSM_FOC_Limit_iDC(maxTrq);
|
|
|
}else if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_SPD){
|
|
|
@@ -508,11 +511,11 @@ void PMSM_FOC_idqCalc(void) {
|
|
|
maxSpeed = eRamp_get_target(&gFoc_Ctrl.in.cruiseRpmRamp);
|
|
|
refSpeed = eRamp_get_intepolation(&gFoc_Ctrl.in.cruiseRpmRamp);//gFoc_Ctrl.in.s_cruiseRPM;
|
|
|
}
|
|
|
- if (maxSpeed > 0) {
|
|
|
- gFoc_Ctrl.pi_speed->max = eRamp_get_intepolation(&gFoc_Ctrl.userLim.phaseCurrLimRamp);//gFoc_Ctrl.userLim.s_PhaseCurrLim;
|
|
|
+ if (maxSpeed >= 0) {
|
|
|
+ gFoc_Ctrl.pi_speed->max = eRamp_get_intepolation(&gFoc_Ctrl.rtLim.phaseCurrLimRamp);//gFoc_Ctrl.userLim.s_PhaseCurrLim;
|
|
|
gFoc_Ctrl.pi_speed->min = -gFoc_Ctrl.userLim.s_PhaseCurreBrkLim;
|
|
|
}else if (maxSpeed < 0) {
|
|
|
- gFoc_Ctrl.pi_speed->min = -eRamp_get_intepolation(&gFoc_Ctrl.userLim.phaseCurrLimRamp);//gFoc_Ctrl.userLim.s_PhaseCurrLim;
|
|
|
+ gFoc_Ctrl.pi_speed->min = -eRamp_get_intepolation(&gFoc_Ctrl.rtLim.phaseCurrLimRamp);//gFoc_Ctrl.userLim.s_PhaseCurrLim;
|
|
|
gFoc_Ctrl.pi_speed->max = gFoc_Ctrl.userLim.s_PhaseCurreBrkLim;
|
|
|
}
|
|
|
|
|
|
@@ -539,20 +542,20 @@ void PMSM_FOC_RunTime_Limit(void) {
|
|
|
dclim = min(dclim, gFoc_Ctrl.userLim.s_iDCLim);
|
|
|
phaselim = min(phaselim, gFoc_Ctrl.userLim.s_PhaseCurrLim);
|
|
|
|
|
|
- if (phaselim != gFoc_Ctrl.userLim.phaseCurrLimRamp.target) {
|
|
|
- eRamp_set_step_target(&gFoc_Ctrl.userLim.phaseCurrLimRamp, phaselim, CONFIG_eCTRL_STEP_TS);
|
|
|
+ if (phaselim < gFoc_Ctrl.rtLim.phaseCurrLimRamp.target) {
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, phaselim, CONFIG_eCTRL_STEP_TS);
|
|
|
}
|
|
|
- if (dclim != gFoc_Ctrl.userLim.DCCurrLimRamp.target) {
|
|
|
- eRamp_set_step_target(&gFoc_Ctrl.userLim.DCCurrLimRamp, dclim, CONFIG_eCTRL_STEP_TS);
|
|
|
+ if (dclim < gFoc_Ctrl.rtLim.DCCurrLimRamp.target) {
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, dclim, CONFIG_eCTRL_STEP_TS);
|
|
|
}
|
|
|
gFoc_Ctrl.protLim.s_iDCLim = dclim;
|
|
|
gFoc_Ctrl.protLim.s_PhaseCurrLim = phaselim;
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_Slow_Task(void) {
|
|
|
- eRamp_running(&gFoc_Ctrl.userLim.phaseCurrLimRamp);
|
|
|
- eRamp_running(&gFoc_Ctrl.userLim.rpmLimRamp);
|
|
|
- eRamp_running(&gFoc_Ctrl.userLim.DCCurrLimRamp);
|
|
|
+ eRamp_running(&gFoc_Ctrl.rtLim.phaseCurrLimRamp);
|
|
|
+ eRamp_running(&gFoc_Ctrl.rtLim.rpmLimRamp);
|
|
|
+ eRamp_running(&gFoc_Ctrl.rtLim.DCCurrLimRamp);
|
|
|
eRamp_running(&gFoc_Ctrl.in.cruiseRpmRamp);
|
|
|
|
|
|
PMSM_FOC_idqCalc();
|
|
|
@@ -567,6 +570,7 @@ void PMSM_FOC_Start(u8 nCtrlMode) {
|
|
|
return;
|
|
|
}
|
|
|
PMSM_FOC_CoreInit();
|
|
|
+ eCtrl_Reset();
|
|
|
gFoc_Ctrl.in.n_ctlMode = nCtrlMode;
|
|
|
gFoc_Ctrl.in.b_motEnable = true;
|
|
|
}
|
|
|
@@ -584,13 +588,13 @@ bool PMSM_FOC_Is_Start(void) {
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_DCCurrLimit(float ibusLimit) {
|
|
|
- if (ibusLimit > gFoc_Ctrl.hwLim.s_iDCMax) {
|
|
|
- ibusLimit = gFoc_Ctrl.hwLim.s_iDCMax;
|
|
|
+ float minCurr = min(gFoc_Ctrl.hwLim.s_iDCMax, gFoc_Ctrl.protLim.s_iDCLim);
|
|
|
+ if (ibusLimit > minCurr) {
|
|
|
+ ibusLimit = minCurr;
|
|
|
}
|
|
|
gFoc_Ctrl.userLim.s_iDCLim = (ibusLimit);
|
|
|
- if (ibusLimit <= gFoc_Ctrl.protLim.s_iDCLim) {
|
|
|
- eRamp_set_step_target(&gFoc_Ctrl.userLim.DCCurrLimRamp, ibusLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
- }
|
|
|
+
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, ibusLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
}
|
|
|
|
|
|
float PMSM_FOC_GetDCCurrLimit(void) {
|
|
|
@@ -602,7 +606,7 @@ void PMSM_FOC_SpeedLimit(float speedLimit) {
|
|
|
speedLimit = gFoc_Ctrl.hwLim.s_motRPMMax;
|
|
|
}
|
|
|
gFoc_Ctrl.userLim.s_motRPMLim = (speedLimit);
|
|
|
- eRamp_set_step_target(&gFoc_Ctrl.userLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
}
|
|
|
|
|
|
float PMSM_FOC_GetSpeedLimit(void) {
|
|
|
@@ -654,14 +658,21 @@ u8 PMSM_FOC_GetCtrlMode(void) {
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_PhaseCurrLim(float lim) {
|
|
|
- if (lim > gFoc_Ctrl.hwLim.s_PhaseCurrMax) {
|
|
|
- lim = gFoc_Ctrl.hwLim.s_PhaseCurrMax;
|
|
|
+ float minCurr = min(gFoc_Ctrl.hwLim.s_PhaseCurrMax, gFoc_Ctrl.protLim.s_PhaseCurrLim);
|
|
|
+ if (lim > minCurr) {
|
|
|
+ lim = minCurr;
|
|
|
}
|
|
|
gFoc_Ctrl.userLim.s_PhaseCurrLim = lim;
|
|
|
|
|
|
- if (lim <= gFoc_Ctrl.protLim.s_PhaseCurrLim) {
|
|
|
- eRamp_set_step_target(&gFoc_Ctrl.userLim.phaseCurrLimRamp, lim, CONFIG_eCTRL_STEP_TS);
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, lim, CONFIG_eCTRL_STEP_TS);
|
|
|
+}
|
|
|
+
|
|
|
+void PMSM_FOC_RT_PhaseCurrLim(float lim) {
|
|
|
+ float minCurr = min(gFoc_Ctrl.hwLim.s_PhaseCurrMax, gFoc_Ctrl.protLim.s_PhaseCurrLim);
|
|
|
+ if (lim > minCurr) {
|
|
|
+ lim = minCurr;
|
|
|
}
|
|
|
+ eRamp_init_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, lim, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
}
|
|
|
|
|
|
float PMSM_FOC_GetPhaseCurrLim(void) {
|