From 267fa5c341288bf96e45895076eb55aecb73b2d5 Mon Sep 17 00:00:00 2001 From: jsphuebner Date: Sun, 6 Nov 2022 16:13:37 +0100 Subject: [PATCH] Allow idMTPA to be 2x iqMTPA Allow minimum attenuation to be 5% (before 10%) --- src/pwmgeneration-foc.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp index b86a9ae..49a2cbd 100644 --- a/src/pwmgeneration-foc.cpp +++ b/src/pwmgeneration-foc.cpp @@ -62,18 +62,21 @@ void PwmGeneration::Run() { int amplitudeErr = (FOC::GetMaximumModulationIndex() - Param::GetInt(Param::vlimmargin)) - Param::GetInt(Param::amp); amplitudeErr = MIN(fwOutMax, amplitudeErr); - amplitudeErr = MAX(fwOutMax / 10, amplitudeErr); + amplitudeErr = MAX(fwOutMax / 20, amplitudeErr); amplitudeErrFiltered = IIRFILTER(amplitudeErrFiltered, amplitudeErr << 8, Param::GetInt(Param::vlimflt)); int fwPermille = amplitudeErrFiltered >> 8; s32fp ifw = Param::Get(Param::manualifw) + ((fwOutMax - fwPermille) * Param::Get(Param::fwcurmax)) / fwOutMax; Param::SetFixed(Param::ifw, ifw); - idMtpa = (fwPermille * idMtpa) / fwOutMax; - dController.SetRef(idMtpa + ifw); s32fp limitedIq = (fwPermille * iqMtpa) / fwOutMax; qController.SetRef(limitedIq); + + s32fp limitedId = -2 * ABS(limitedIq); //ratio between id and iq never > 2 + limitedId = MAX(idMtpa, limitedId); + limitedId = MIN(ifw, limitedId); + dController.SetRef(limitedId); } - if (opmode == MOD_MANUAL) + else if (opmode == MOD_MANUAL) { dController.SetRef(Param::Get(Param::manualid)); qController.SetRef(Param::Get(Param::manualiq));