|
|
@@ -15,7 +15,7 @@
|
|
|
#include "math/fir.h"
|
|
|
PMSM_FOC_Ctrl _gFOC_Ctrl;
|
|
|
static Fir_t phase1, phase2;
|
|
|
-
|
|
|
+static bool g_focinit = false;
|
|
|
static __INLINE void RevPark(DQ_t *dq, float angle, AB_t *alpha_beta) {
|
|
|
float c,s;
|
|
|
#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);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+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) {
|
|
|
Fir_init(&phase1);
|
|
|
Fir_init(&phase2);
|
|
|
@@ -172,23 +185,18 @@ void PMSM_FOC_CoreInit(void) {
|
|
|
|
|
|
memset(&_gFOC_Ctrl.in, 0, sizeof(_gFOC_Ctrl.in));
|
|
|
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_motRPMMax = CONFIG_MAX_MOT_RPM;
|
|
|
_gFOC_Ctrl.hwLim.s_PhaseCurrMax = CONFIG_MAX_PHASE_CURR;
|
|
|
_gFOC_Ctrl.hwLim.s_PhaseVolMax = CONFIG_MAX_PHASE_VOL;
|
|
|
_gFOC_Ctrl.hwLim.s_vDCMax = CONFIG_MAX_VBUS_VOLTAGE;
|
|
|
_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_PhaseFilterCeof = nv_get_foc_params()->n_PhaseFilterCeof;//(0.2f);
|
|
|
//_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;
|
|
|
}
|
|
|
|
|
|
+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) {
|
|
|
FOC_Set_vDqRamp(&_gFOC_Ctrl.vdq_ctl[0], vd);
|