|
|
@@ -180,7 +180,7 @@ static void PMSM_FOC_UserInit(void) {
|
|
|
gFoc_Ctrl.userLim.s_vDCMaxLim = nv_get_foc_params()->s_maxDCVol;
|
|
|
gFoc_Ctrl.userLim.s_vDCMinLim = nv_get_foc_params()->s_minDCVol;
|
|
|
gFoc_Ctrl.userLim.s_iDCeBrkLim = nv_get_foc_params()->s_iDCeBrkLim;
|
|
|
- gFoc_Ctrl.userLim.s_PhaseCurreBrkLim = nv_get_foc_params()->s_PhaseCurreBrkLim;
|
|
|
+ gFoc_Ctrl.userLim.s_TorqueBrkLim = nv_get_foc_params()->s_TorqueBrkLim;
|
|
|
gFoc_Ctrl.userLim.s_PhaseVoleBrkLim = gFoc_Ctrl.hwLim.s_PhaseVolMax;
|
|
|
}
|
|
|
|
|
|
@@ -222,7 +222,7 @@ void PMSM_FOC_CoreInit(void) {
|
|
|
g_focinit = true;
|
|
|
_DEBUG("User Limit:\n");
|
|
|
_DEBUG("dc %f, rpm %f, torque %f, phase %f, vDCmax %f, vDCmin %f, ebrk %f\n", gFoc_Ctrl.userLim.s_iDCLim, gFoc_Ctrl.userLim.s_motRPMLim, gFoc_Ctrl.userLim.s_torqueLim,
|
|
|
- gFoc_Ctrl.userLim.s_PhaseCurrLim, gFoc_Ctrl.userLim.s_vDCMaxLim, gFoc_Ctrl.userLim.s_vDCMinLim, gFoc_Ctrl.userLim.s_PhaseCurreBrkLim);
|
|
|
+ gFoc_Ctrl.userLim.s_PhaseCurrLim, gFoc_Ctrl.userLim.s_vDCMaxLim, gFoc_Ctrl.userLim.s_vDCMinLim, gFoc_Ctrl.userLim.s_TorqueBrkLim);
|
|
|
_DEBUG("Hw Limit:\n");
|
|
|
_DEBUG("dc %f, rpm %f, torque %f, phase %f\n", gFoc_Ctrl.hwLim.s_iDCMax, gFoc_Ctrl.hwLim.s_motRPMMax, gFoc_Ctrl.hwLim.s_torqueMax, gFoc_Ctrl.hwLim.s_PhaseCurrMax);
|
|
|
}
|
|
|
@@ -483,9 +483,13 @@ u8 PMSM_FOC_CtrlMode(void) {
|
|
|
PI_Controller_Reset(&gFoc_Ctrl.pi_torque, gFoc_Ctrl.in.s_targetTorque);
|
|
|
#endif
|
|
|
}else if ((preMode == CTRL_MODE_TRQ) && (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE)) {
|
|
|
+#if 0
|
|
|
float real_trq = PMSM_FOC_Get_Real_dqVector() * 0.9f;
|
|
|
eCtrl_reset_Current(min(real_trq, gFoc_Ctrl.in.s_targetTorque));
|
|
|
- eCtrl_set_TgtCurrent(-PMSM_FOC_GeteBrkPhaseCurrent());
|
|
|
+ eCtrl_set_TgtCurrent(-PMSM_FOC_GetEbrkTorque());
|
|
|
+#else
|
|
|
+ eCtrl_set_TgtTorque(-PMSM_FOC_GetEbrkTorque());
|
|
|
+#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -552,7 +556,7 @@ static __INLINE float PMSM_FOC_Limit_Speed(float maxTrq) {
|
|
|
}
|
|
|
|
|
|
static __INLINE void PMSM_FOC_idq_Assign(void) {
|
|
|
- if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT || gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE) {
|
|
|
+ if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT) {
|
|
|
if (gFoc_Ctrl.in.b_MTPA_calibrate && (gFoc_Ctrl.in.s_manualAngle != INVALID_ANGLE)) {
|
|
|
float s, c;
|
|
|
normal_sincosf(degree_2_pi(gFoc_Ctrl.in.s_manualAngle + 90.0f), &s, &c);
|
|
|
@@ -568,7 +572,8 @@ static __INLINE void PMSM_FOC_idq_Assign(void) {
|
|
|
gFoc_Ctrl.in.s_targetIdq.d = 0;
|
|
|
gFoc_Ctrl.in.s_targetIdq.q = gFoc_Ctrl.in.s_targetCurrent;
|
|
|
}
|
|
|
- }else if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) || (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_SPD)) {
|
|
|
+ }else if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) || (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_SPD) ||
|
|
|
+ (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE)) {
|
|
|
trq2dq_lookup((int)gFoc_Ctrl.in.s_motRPM, gFoc_Ctrl.in.s_targetTorque, &gFoc_Ctrl.in.s_targetIdq);
|
|
|
PMSM_FOC_FieldWeak();
|
|
|
}
|
|
|
@@ -589,13 +594,14 @@ void PMSM_FOC_idqCalc(void) {
|
|
|
PMSM_FOC_idq_Assign();
|
|
|
return;
|
|
|
}
|
|
|
- if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT) || (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE)) {
|
|
|
+ if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT) {
|
|
|
gFoc_Ctrl.in.s_targetCurrent = eCtrl_get_RefCurrent();
|
|
|
- if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE) {
|
|
|
- if (eCtrl_get_FinalCurrent() < 0.0001f && gFoc_Ctrl.in.s_motRPM < CONFIG_MIN_RPM_EXIT_EBRAKE) {
|
|
|
- gFoc_Ctrl.in.s_targetCurrent = 0;
|
|
|
- }
|
|
|
+ }else if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_EBRAKE) {
|
|
|
+ float maxTrq = eCtrl_get_RefTorque();
|
|
|
+ if (eCtrl_get_FinalTorque() < 0.0001f && gFoc_Ctrl.in.s_motRPM < CONFIG_MIN_RPM_EXIT_EBRAKE) {
|
|
|
+ maxTrq = 0;
|
|
|
}
|
|
|
+ crosszero_step_towards(&gFoc_Ctrl.in.s_targetTorque, maxTrq);
|
|
|
}else if (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) {
|
|
|
float refTorque = min(eCtrl_get_RefTorque(), eRamp_get_intepolation(&gFoc_Ctrl.rtLim.torqueLimRamp));
|
|
|
float maxTrq = PMSM_FOC_Limit_Speed(refTorque);
|
|
|
@@ -773,13 +779,13 @@ float PMSM_FOC_GetTorqueLimit(void) {
|
|
|
return gFoc_Ctrl.userLim.s_torqueLim;
|
|
|
}
|
|
|
|
|
|
-void PMSM_FOC_SeteBrkPhaseCurrent(float phase_curr, float dc_curr) {
|
|
|
- gFoc_Ctrl.userLim.s_PhaseCurreBrkLim = fclamp(phase_curr, 0, nv_get_foc_params()->s_PhaseCurreBrkLim);
|
|
|
+void PMSM_FOC_SetEbrkTorque(float phase_curr, float dc_curr) {
|
|
|
+ gFoc_Ctrl.userLim.s_TorqueBrkLim = fclamp(phase_curr, 0, nv_get_foc_params()->s_TorqueBrkLim);
|
|
|
gFoc_Ctrl.userLim.s_iDCeBrkLim = fclamp(dc_curr, 0, nv_get_foc_params()->s_iDCeBrkLim);
|
|
|
}
|
|
|
|
|
|
-float PMSM_FOC_GeteBrkPhaseCurrent(void) {
|
|
|
- return gFoc_Ctrl.userLim.s_PhaseCurreBrkLim ;
|
|
|
+float PMSM_FOC_GetEbrkTorque(void) {
|
|
|
+ return gFoc_Ctrl.userLim.s_TorqueBrkLim;
|
|
|
}
|
|
|
|
|
|
float PMSM_FOC_GetVbusVoltage(void) {
|
|
|
@@ -871,50 +877,6 @@ bool PMSM_FOC_Set_Speed(float rpm) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-bool PMSM_FOC_Set_epmMode(bool epm) {
|
|
|
- if (epm && !gFoc_Ctrl.in.b_motEnable) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (gFoc_Ctrl.in.b_epmMode != epm) {
|
|
|
- if (PMSM_FOC_GetSpeed() != 0.0f) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
|
|
|
- return false;
|
|
|
- }
|
|
|
- gFoc_Ctrl.in.epmDirection = EPM_Dir_None;
|
|
|
- gFoc_Ctrl.in.b_epmMode = epm;
|
|
|
- if (epm) {
|
|
|
- PMSM_FOC_SpeedLimit(nv_get_foc_params()->s_maxEpmRPM);
|
|
|
- eCtrl_set_TgtSpeed(0);
|
|
|
- PMSM_FOC_SetCtrlMode(CTRL_MODE_SPD);
|
|
|
- }else {
|
|
|
- PMSM_FOC_SetCtrlMode(CTRL_MODE_TRQ);
|
|
|
- PMSM_FOC_SpeedLimit(nv_get_foc_params()->s_maxRPM);
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool PMSM_FOC_Start_epmMove(bool move, EPM_Dir_t dir) {
|
|
|
- if (!gFoc_Ctrl.in.b_epmMode) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (move) {
|
|
|
- if (gFoc_Ctrl.in.epmDirection != EPM_Dir_None) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- gFoc_Ctrl.in.epmDirection = dir;
|
|
|
- }else {
|
|
|
- gFoc_Ctrl.in.epmDirection = EPM_Dir_None;
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-EPM_Dir_t PMSM_FOC_Get_epmDir(void) {
|
|
|
- return gFoc_Ctrl.in.epmDirection;
|
|
|
-}
|
|
|
-#endif
|
|
|
|
|
|
bool PMSM_FOC_Set_Current(float is) {
|
|
|
if (is > gFoc_Ctrl.userLim.s_PhaseCurrLim) {
|
|
|
@@ -959,7 +921,6 @@ void PMSM_FOC_MTPA_Calibrate(bool enable) {
|
|
|
if (enable) {
|
|
|
gFoc_Ctrl.in.b_MTPA_calibrate = true;
|
|
|
gFoc_Ctrl.in.s_manualAngle = 0;
|
|
|
- eCtrl_set_ebrk_time(CONFIG_MTPA_CALI_RAMP_TIME);
|
|
|
}else {
|
|
|
gFoc_Ctrl.in.s_manualAngle = INVALID_ANGLE;
|
|
|
gFoc_Ctrl.in.b_MTPA_calibrate = false;
|