|
|
@@ -176,6 +176,7 @@ static void PMSM_FOC_UserInit(void) {
|
|
|
gFoc_Ctrl.userLim.s_PhaseVoleBrkLim = gFoc_Ctrl.hwLim.s_PhaseVolMax;
|
|
|
eRamp_init_target(&gFoc_Ctrl.userLim.rpmLimRamp, gFoc_Ctrl.userLim.s_motRPMLim);
|
|
|
eRamp_init_target(&gFoc_Ctrl.userLim.phaseCurrLimRamp, gFoc_Ctrl.userLim.s_PhaseCurrLim);
|
|
|
+ eRamp_init_target(&gFoc_Ctrl.userLim.DCCurrLimRamp, gFoc_Ctrl.userLim.s_iDCLim);
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_CoreInit(void) {
|
|
|
@@ -387,7 +388,7 @@ u8 PMSM_FOC_CtrlMode(void) {
|
|
|
static __INLINE float PMSM_FOC_Limit_Power(float maxTrq) {
|
|
|
#if 0
|
|
|
PI_Ctrl_Power.max = maxTrq;
|
|
|
- float errRef = gFoc_Ctrl.userLim.s_iDCLim - gFoc_Ctrl.out.s_FilteriDC;
|
|
|
+ float errRef = eRamp_get_intepolation(&gFoc_Ctrl.userLim.DCCurrLimRamp) - gFoc_Ctrl.out.s_FilteriDC;
|
|
|
return PI_Controller_run(gFoc_Ctrl.pi_power, errRef);
|
|
|
#else
|
|
|
return maxTrq;
|
|
|
@@ -463,6 +464,20 @@ void PMSM_FOC_idqCalc(void) {
|
|
|
void PMSM_FOC_Slow_Task(void) {
|
|
|
eRamp_running(&gFoc_Ctrl.userLim.phaseCurrLimRamp);
|
|
|
eRamp_running(&gFoc_Ctrl.userLim.rpmLimRamp);
|
|
|
+ eRamp_running(&gFoc_Ctrl.userLim.DCCurrLimRamp);
|
|
|
+
|
|
|
+ if (gFoc_Ctrl.out.n_CritiCalErrMask != gFoc_Ctrl.out.n_CritiCalErrPrev) {
|
|
|
+ /* 欠压降速,限制相电流 */
|
|
|
+ if (!(gFoc_Ctrl.out.n_CritiCalErrPrev & gFoc_Ctrl.out.n_CritiCalErrMask) && (FOC_CRIT_UN_Vol_Err & gFoc_Ctrl.out.n_CritiCalErrMask)) {
|
|
|
+ if (gFoc_Ctrl.userLim.s_motRPMLim > CONFIG_UNDER_VOL_RPM) {
|
|
|
+ PMSM_FOC_SpeedLimit(CONFIG_UNDER_VOL_RPM);
|
|
|
+ }
|
|
|
+ if (gFoc_Ctrl.userLim.s_iDCLim > CONFIG_UNDER_VOL_DC_CURR) {
|
|
|
+ PMSM_FOC_DCCurrLimit(CONFIG_UNDER_VOL_DC_CURR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ gFoc_Ctrl.out.n_CritiCalErrPrev = gFoc_Ctrl.out.n_CritiCalErrMask;
|
|
|
+ }
|
|
|
PMSM_FOC_idqCalc();
|
|
|
}
|
|
|
|
|
|
@@ -491,19 +506,32 @@ bool PMSM_FOC_Is_Start(void) {
|
|
|
return gFoc_Ctrl.in.b_motEnable;
|
|
|
}
|
|
|
|
|
|
-void PMSM_FOC_iBusLimit(float ibusLimit) {
|
|
|
+void PMSM_FOC_DCCurrLimit(float ibusLimit) {
|
|
|
+ if (ibusLimit > gFoc_Ctrl.hwLim.s_iDCMax) {
|
|
|
+ ibusLimit = gFoc_Ctrl.hwLim.s_iDCMax;
|
|
|
+ }
|
|
|
+ if (gFoc_Ctrl.out.n_CritiCalErrMask & FOC_CRIT_UN_Vol_Err) {
|
|
|
+ if (ibusLimit > CONFIG_UNDER_VOL_DC_CURR) {
|
|
|
+ ibusLimit = CONFIG_UNDER_VOL_DC_CURR;
|
|
|
+ }
|
|
|
+ }
|
|
|
gFoc_Ctrl.userLim.s_iDCLim = (ibusLimit);
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.userLim.DCCurrLimRamp, ibusLimit, CONFIG_eCTRL_STEP_TS, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
}
|
|
|
|
|
|
-float PMSM_FOC_GetiBusLimit(void) {
|
|
|
+float PMSM_FOC_GetDCCurrLimit(void) {
|
|
|
return gFoc_Ctrl.userLim.s_iDCLim;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void PMSM_FOC_SpeedLimit(float speedLimit) {
|
|
|
if (speedLimit > gFoc_Ctrl.hwLim.s_motRPMMax) {
|
|
|
speedLimit = gFoc_Ctrl.hwLim.s_motRPMMax;
|
|
|
}
|
|
|
+ if (gFoc_Ctrl.out.n_CritiCalErrMask & FOC_CRIT_UN_Vol_Err) {
|
|
|
+ if (speedLimit > CONFIG_UNDER_VOL_RPM) {
|
|
|
+ speedLimit = CONFIG_UNDER_VOL_RPM;
|
|
|
+ }
|
|
|
+ }
|
|
|
gFoc_Ctrl.userLim.s_motRPMLim = (speedLimit);
|
|
|
eRamp_set_step_target(&gFoc_Ctrl.userLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
}
|
|
|
@@ -568,6 +596,11 @@ void PMSM_FOC_PhaseCurrLim(float lim) {
|
|
|
if (lim > gFoc_Ctrl.hwLim.s_PhaseCurrMax) {
|
|
|
lim = gFoc_Ctrl.hwLim.s_PhaseCurrMax;
|
|
|
}
|
|
|
+ if (gFoc_Ctrl.out.n_CritiCalErrMask & FOC_CRIT_UN_Vol_Err) {
|
|
|
+ if (lim > CONFIG_UNDER_VOL_PHASE_CURR) {
|
|
|
+ lim = CONFIG_UNDER_VOL_PHASE_CURR;
|
|
|
+ }
|
|
|
+ }
|
|
|
gFoc_Ctrl.userLim.s_PhaseCurrLim = lim;
|
|
|
eRamp_set_step_target(&gFoc_Ctrl.userLim.phaseCurrLimRamp, lim, CONFIG_eCTRL_STEP_TS, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
}
|