diff --git a/include/param_prj.h b/include/param_prj.h
index 5afac2d..3a12ffe 100644
--- a/include/param_prj.h
+++ b/include/param_prj.h
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-#define VER 5.32.R
+#define VER 5.33.R
/* Entries should be ordered as follows:
1. Saveable parameters
@@ -71,10 +71,10 @@
PARAM_ENTRY(CAT_INVERTER,udcgain, "dig/V", 0, 4095, 6.175, 29 ) \
PARAM_ENTRY(CAT_INVERTER,udcofs, "dig", 0, 4095, 0, 77 ) \
PARAM_ENTRY(CAT_INVERTER,udclim, "V", 0, 1000, 540, 48 ) \
- PARAM_ENTRY(CAT_INVERTER,snshs, SNS_HS, 0, 7, 0, 45 )
+ PARAM_ENTRY(CAT_INVERTER,snshs, SNS_HS, 0, 7, 0, 45 ) \
+ PARAM_ENTRY(CAT_INVERTER,pinswap, SWAPS, 0, 15, 0, 109 ) \
#define INVERTER_PARAMETERS_FOC \
- PARAM_ENTRY(CAT_INVERTER,pinswap, SWAPS, 0, 15, 0, 109 ) \
PARAM_ENTRY(CAT_INVERTER,modmax, "dig", 37000, 45000, 37836, 148 )
#define DERATE_PARAMETERS_COMMON \
diff --git a/include/pwmgeneration.h b/include/pwmgeneration.h
index f79726a..aed1e9e 100644
--- a/include/pwmgeneration.h
+++ b/include/pwmgeneration.h
@@ -20,6 +20,7 @@
#define PWMGENERATION_H
#include
+#include
#include "my_fp.h"
#include "anain.h"
@@ -74,6 +75,7 @@ class PwmGeneration
static int opmode;
static s32fp ilofs[2];
static int polePairRatio;
+ static tim_oc_id ocChannels[3];
};
#endif // PWMGENERATION_H
diff --git a/include/throttle.h b/include/throttle.h
index 19c8903..58c4082 100644
--- a/include/throttle.h
+++ b/include/throttle.h
@@ -25,7 +25,7 @@
class Throttle
{
public:
- static bool CheckAndLimitRange(int* potval, int potIdx);
+ static bool CheckAndLimitRange(int* potval, uint8_t potIdx);
static float DigitsToPercent(int potval, int potidx);
static float CalcThrottle(float potval, float pot2val, bool brkpedal, float rotorHz);
static float CalcThrottleBiDir(float potval, bool brkpedal);
diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp
index 5324cb3..5d96ecb 100644
--- a/src/pwmgeneration-foc.cpp
+++ b/src/pwmgeneration-foc.cpp
@@ -44,7 +44,6 @@ static const s32fp dcCurFac = FP_FROMFLT(0.81649658092772603273 * 1.05); //sqrt(
static const int32_t fwOutMax = 1024;
static const uint32_t shiftForFilter = 8;
static s32fp idMtpa = 0, iqMtpa = 0;
-static tim_oc_id ocChannels[3];
static PiController qController;
static PiController dController;
static s32fp fwCurMax = 0;
@@ -186,25 +185,6 @@ void PwmGeneration::PwmInit()
dController.SetCallingFrequency(pwmfrq);
dController.SetMinMaxY(-maxVd, maxVd);
- if ((Param::GetInt(Param::pinswap) & SWAP_PWM13) > 0)
- {
- ocChannels[0] = TIM_OC3;
- ocChannels[1] = TIM_OC2;
- ocChannels[2] = TIM_OC1;
- }
- else if ((Param::GetInt(Param::pinswap) & SWAP_PWM23) > 0)
- {
- ocChannels[0] = TIM_OC1;
- ocChannels[1] = TIM_OC3;
- ocChannels[2] = TIM_OC2;
- }
- else
- {
- ocChannels[0] = TIM_OC1;
- ocChannels[1] = TIM_OC2;
- ocChannels[2] = TIM_OC3;
- }
-
if (opmode == MOD_ACHEAT)
AcHeatTimerSetup();
}
diff --git a/src/pwmgeneration-sine.cpp b/src/pwmgeneration-sine.cpp
index 9e12cc2..f54cf5c 100644
--- a/src/pwmgeneration-sine.cpp
+++ b/src/pwmgeneration-sine.cpp
@@ -68,9 +68,10 @@ void PwmGeneration::Run()
}
/* Match to PWM resolution */
- timer_set_oc_value(PWM_TIMER, TIM_OC1, SineCore::DutyCycles[0] >> shiftForTimer);
- timer_set_oc_value(PWM_TIMER, TIM_OC2, SineCore::DutyCycles[1] >> shiftForTimer);
- timer_set_oc_value(PWM_TIMER, TIM_OC3, SineCore::DutyCycles[2] >> shiftForTimer);
+ for (int i = 0; i < 3; i++)
+ {
+ timer_set_oc_value(PWM_TIMER, ocChannels[i], SineCore::DutyCycles[i] >> shiftForTimer);
+ }
}
else if (opmode == MOD_BOOST || opmode == MOD_BUCK)
{
diff --git a/src/pwmgeneration.cpp b/src/pwmgeneration.cpp
index 139bb7e..3e7b0ad 100644
--- a/src/pwmgeneration.cpp
+++ b/src/pwmgeneration.cpp
@@ -36,17 +36,18 @@
#define DIGIT_TO_DEGREE(a) FP_FROMINT(angle) / (65536 / 360)
#define FRQ_DIVIDER 8192 //PWM ISR callback frequency divider
-uint16_t PwmGeneration::pwmfrq = 1;
-uint16_t PwmGeneration::angle;
-s32fp PwmGeneration::ampnom;
-s32fp PwmGeneration::fslip;
-s32fp PwmGeneration::frq;
-s32fp PwmGeneration::frqFiltered;
-uint8_t PwmGeneration::shiftForTimer;
-int PwmGeneration::opmode;
-s32fp PwmGeneration::ilofs[2];
-int PwmGeneration::polePairRatio;
-int16_t PwmGeneration::slipIncr;
+uint16_t PwmGeneration::pwmfrq = 1;
+uint16_t PwmGeneration::angle;
+s32fp PwmGeneration::ampnom;
+s32fp PwmGeneration::fslip;
+s32fp PwmGeneration::frq;
+s32fp PwmGeneration::frqFiltered;
+uint8_t PwmGeneration::shiftForTimer;
+int PwmGeneration::opmode;
+s32fp PwmGeneration::ilofs[2];
+int PwmGeneration::polePairRatio;
+int16_t PwmGeneration::slipIncr;
+tim_oc_id PwmGeneration::ocChannels[3];
static int execTicks;
static bool tripped;
@@ -370,6 +371,25 @@ uint16_t PwmGeneration::TimerSetup(uint16_t deadtime, bool activeLow)
const uint16_t pwmmax = 1U << pwmdigits;
const uint8_t outputMode = activeLow ? GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN : GPIO_CNF_OUTPUT_ALTFN_PUSHPULL;
+ if ((Param::GetInt(Param::pinswap) & SWAP_PWM13) > 0)
+ {
+ ocChannels[0] = TIM_OC3;
+ ocChannels[1] = TIM_OC2;
+ ocChannels[2] = TIM_OC1;
+ }
+ else if ((Param::GetInt(Param::pinswap) & SWAP_PWM23) > 0)
+ {
+ ocChannels[0] = TIM_OC1;
+ ocChannels[1] = TIM_OC3;
+ ocChannels[2] = TIM_OC2;
+ }
+ else
+ {
+ ocChannels[0] = TIM_OC1;
+ ocChannels[1] = TIM_OC2;
+ ocChannels[2] = TIM_OC3;
+ }
+
//Disable output in active low mode before resetting timer, otherwise shoot through will occur!
if (activeLow)
{
diff --git a/src/throttle.cpp b/src/throttle.cpp
index 23c5fe9..8483af7 100644
--- a/src/throttle.cpp
+++ b/src/throttle.cpp
@@ -55,7 +55,7 @@ int Throttle::accelflt;
float Throttle::maxregentravelhz;
float Throttle::regenrampstr;
-bool Throttle::CheckAndLimitRange(int* potval, int potIdx)
+bool Throttle::CheckAndLimitRange(int* potval, uint8_t potIdx)
{
int potMin = potmax[potIdx] > potmin[potIdx] ? potmin[potIdx] : potmax[potIdx];
int potMax = potmax[potIdx] > potmin[potIdx] ? potmax[potIdx] : potmin[potIdx];
@@ -87,10 +87,10 @@ float Throttle::DigitsToPercent(int potval, int potidx)
/**
- * Calculate throttle and regen.
+ * Calculate throttle and regen.
* - Increase regentravel when lifting accelerator using historical pedal values.
* - Decrease regentravel when speed goes below regenrampstr.
- *
+ *
* Parameters:
* potnom = accelerator pedal pressed percentage
* pot2nom = optional potentiometer for adjusting regen braking
@@ -134,7 +134,7 @@ float Throttle::CalcThrottle(float potnom, float pot2nom, bool brkpedal, float r
}
// increase currentRegenTravel when lifting accelerator
- if (currentRegentravel < speedBasedRegenTravel) // if currentregentravel is smaller than speedBaseRegenTravel
+ if (currentRegentravel < speedBasedRegenTravel) // if currentregentravel is smaller than speedBaseRegenTravel
{
// current pedal position delta compared against average of last 200ms
float acceleratorDelta = potnom - potnomSums / history;