diff --git a/include/param_prj.h b/include/param_prj.h
index 631446d..8c7569d 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.11.R
+#define VER 5.12.R
/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
@@ -37,7 +37,7 @@
PARAM_ENTRY(CAT_MOTOR, numimp, "ppr", 8, 8192, 60, 15 ) \
PARAM_ENTRY(CAT_MOTOR, dirchrpm, "rpm", 0, 20000, 100, 87 ) \
PARAM_ENTRY(CAT_MOTOR, dirmode, DIRMODES, 0, 4, 1, 95 ) \
- PARAM_ENTRY(CAT_MOTOR, snsm, SNS_M, 12, 21, 12, 46 )
+ PARAM_ENTRY(CAT_MOTOR, snsm, SNS_M, 12, 22, 12, 46 )
#define MOTOR_PARAMETERS_SINE \
PARAM_ENTRY(CAT_MOTOR, boost, "dig", 0, 37813, 1700, 1 ) \
@@ -244,7 +244,7 @@
#define DIRS "-1=Reverse, 0=Neutral, 1=Forward"
#define TRIPMODES "0=AllOff, 1=DcSwOn, 2=PrechargeOn, 3=AutoResume"
#define SNS_HS "0=JCurve, 1=Semikron, 2=MBB600, 3=KTY81, 4=PT1000, 5=NTCK45_2k2, 6=Leaf, 7=BMW-i3"
-#define SNS_M "12=KTY83-110, 13=KTY84-130, 14=Leaf, 15=KTY81-110, 16=Toyota, 21=OutlanderFront"
+#define SNS_M "12=KTY83-110, 13=KTY84-130, 14=Leaf, 15=KTY81-110, 16=Toyota, 21=OutlanderFront, 22=EpcosB57861-S"
#define PWMFUNCS "0=tmpm, 1=tmphs, 2=speed, 3=speedfrq"
#define BTNSWITCH "0=Button, 1=Switch, 2=CAN"
#define DIRMODES "0=Button, 1=Switch, 2=ButtonReversed, 3=SwitchReversed, 4=DefaultForward"
diff --git a/include/pwmgeneration.h b/include/pwmgeneration.h
index 46c0868..d556105 100644
--- a/include/pwmgeneration.h
+++ b/include/pwmgeneration.h
@@ -32,7 +32,7 @@ class PwmGeneration
static void SetOpmode(int opmode);
static void SetAmpnom(s32fp amp);
static void SetFslip(s32fp fslip);
- static void SetTorquePercent(s32fp torque);
+ static void SetTorquePercent(float torque);
static void SetCurrentOffset(int offset1, int offset2);
static void SetCurrentLimitThreshold(s32fp ocurlim);
static void SetControllerGains(int kp, int ki, int fwkp);
diff --git a/include/temp_meas.h b/include/temp_meas.h
index 29b53c7..bdcfeae 100644
--- a/include/temp_meas.h
+++ b/include/temp_meas.h
@@ -19,8 +19,6 @@
#ifndef TEMP_MEAS_H_INCLUDED
#define TEMP_MEAS_H_INCLUDED
-#include "my_fp.h"
-
class TempMeas
{
public:
@@ -45,6 +43,7 @@ class TempMeas
TEMP_TESLA_LDU_FLUID = 19,
TEMP_TESLA_10K = 20,
TEMP_OUTLANDERFRONT = 21,
+ TEMP_EPCOSB56871 = 22,
TEMP_LAST
};
@@ -580,7 +579,31 @@ class TempMeas
2987 ,\
3002 ,\
3016 ,\
-3027
+3027
+
+#define EPCOSB57861 \
+8 ,\
+14 ,\
+25 ,\
+42 ,\
+68 ,\
+107 ,\
+163 ,\
+240 ,\
+340 ,\
+470 ,\
+624 ,\
+808 ,\
+1009 ,\
+1223 ,\
+1437 ,\
+1642 ,\
+1839 ,\
+2020 ,\
+2183 ,\
+2327 ,\
+2454
+
#endif
diff --git a/libopeninv b/libopeninv
index 952921d..dd7d769 160000
--- a/libopeninv
+++ b/libopeninv
@@ -1 +1 @@
-Subproject commit 952921dfab9f9bceb73b04f46879c2888b8a3ebf
+Subproject commit dd7d769bddcacf6fd4bc1af058938a99136e83c0
diff --git a/misc/temp_sensors.ods b/misc/temp_sensors.ods
index 7e8a25c..d858d4e 100644
Binary files a/misc/temp_sensors.ods and b/misc/temp_sensors.ods differ
diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp
index f1e7e06..dcd236f 100644
--- a/src/pwmgeneration-foc.cpp
+++ b/src/pwmgeneration-foc.cpp
@@ -142,14 +142,15 @@ void PwmGeneration::Run()
}
}
-void PwmGeneration::SetTorquePercent(s32fp torquePercent)
+void PwmGeneration::SetTorquePercent(float torquePercent)
{
- s32fp brkrampstr = Param::Get(Param::brkrampstr);
+ float brkrampstr = Param::GetFloat(Param::brkrampstr);
+ float rotorfreq = (float)frq / FRAC_FAC;
int direction = Param::GetInt(Param::dir);
- if (frq < brkrampstr && torquePercent < 0)
+ if (rotorfreq < brkrampstr && torquePercent < 0)
{
- torquePercent = FP_MUL(FP_DIV(frq, brkrampstr), torquePercent);
+ torquePercent = (rotorfreq / brkrampstr) * torquePercent;
}
if (torquePercent < 0)
@@ -157,7 +158,7 @@ void PwmGeneration::SetTorquePercent(s32fp torquePercent)
direction = Encoder::GetRotorDirection();
}
- int32_t is = FP_TOINT(FP_MUL(Param::Get(Param::throtcur), direction * torquePercent));
+ int32_t is = Param::GetFloat(Param::throtcur) * direction * torquePercent;
int32_t id, iq;
FOC::Mtpa(is, id, iq);
diff --git a/src/pwmgeneration-sine.cpp b/src/pwmgeneration-sine.cpp
index 29a68af..d5582f8 100644
--- a/src/pwmgeneration-sine.cpp
+++ b/src/pwmgeneration-sine.cpp
@@ -81,61 +81,63 @@ void PwmGeneration::Run()
}
}
-void PwmGeneration::SetTorquePercent(s32fp torque)
+void PwmGeneration::SetTorquePercent(float torque)
{
- s32fp fslipmin = Param::Get(Param::fslipmin);
- s32fp ampmin = Param::Get(Param::ampmin);
- s32fp slipstart = Param::Get(Param::slipstart);
- s32fp ampnomLocal;
- s32fp fslipspnt = 0;
+ const int filterConst = 4;
+ const float roundingError = ((float)((1 << filterConst) - 1)) / FRAC_FAC;
+ float fslipmin = Param::GetFloat(Param::fslipmin);
+ float ampmin = Param::GetFloat(Param::ampmin);
+ float slipstart = Param::GetFloat(Param::slipstart);
+ float ampnomLocal;
+ float fslipspnt = 0;
if (torque >= 0)
{
/* In async mode first X% throttle commands amplitude, X-100% raises slip */
- ampnomLocal = ampmin + (100 - FP_TOINT(ampmin)) * FP_DIV(torque, slipstart);
+ ampnomLocal = ampmin + (100.0f - ampmin) * torque / slipstart;
if (torque >= slipstart)
{
- s32fp fstat = Param::Get(Param::fstat);
- s32fp fweak = Param::Get(Param::fweakcalc);
- s32fp fslipmax = Param::Get(Param::fslipmax);
+ float fstat = Param::GetFloat(Param::fstat);
+ float fweak = Param::GetFloat(Param::fweakcalc);
+ float fslipmax = Param::GetFloat(Param::fslipmax);
if (fstat > fweak)
{
- s32fp fconst = Param::Get(Param::fconst);
- s32fp fslipconstmax = Param::Get(Param::fslipconstmax);
+ float fconst = Param::GetFloat(Param::fconst);
+ float fslipconstmax = Param::GetFloat(Param::fslipconstmax);
//Basically, for every Hz above fweak we get a fraction of
//the difference between fslipconstmax and fslipmax
//of additional slip
- fslipmax += FP_MUL(FP_DIV(fstat - fweak, fconst - fweak), fslipconstmax - fslipmax);
+ fslipmax += (fstat - fweak) / (fconst - fweak) * (fslipconstmax - fslipmax);
fslipmax = MIN(fslipmax, fslipconstmax); //never exceed fslipconstmax!
}
- s32fp fslipdiff = fslipmax - fslipmin;
- fslipspnt = fslipmin + (FP_MUL(fslipdiff, (torque - slipstart)) / (100 - FP_TOINT(slipstart)));
+ float fslipdiff = fslipmax - fslipmin;
+ fslipspnt = roundingError + fslipmin + (fslipdiff * (torque - slipstart)) / (100.0f - slipstart);
}
else
{
- fslipspnt = fslipmin;
+ fslipspnt = fslipmin + roundingError;
}
}
else
{
- u32fp brkrampstr = (u32fp)Param::Get(Param::brkrampstr);
+ float brkrampstr = Param::GetFloat(Param::brkrampstr);
ampnomLocal = -torque;
fslipspnt = -fslipmin;
if (Encoder::GetRotorFrequency() < brkrampstr)
{
- ampnomLocal = FP_TOINT(FP_DIV(Encoder::GetRotorFrequency(), brkrampstr) * ampnomLocal);
+ ampnomLocal = Encoder::GetRotorFrequency() / brkrampstr * ampnomLocal;
}
}
- ampnomLocal = MIN(ampnomLocal, FP_FROMINT(100));
+ ampnomLocal = MIN(ampnomLocal, 100.0f);
//anticipate sudden changes by filtering
- ampnom = IIRFILTER(ampnom, ampnomLocal, 4);
- fslip = IIRFILTER(fslip, fslipspnt, 4);
+ ampnom = IIRFILTER(ampnom, FP_FROMFLT(ampnomLocal), filterConst);
+ fslip = IIRFILTER(fslip, FP_FROMFLT(fslipspnt), filterConst);
Param::Set(Param::ampnom, ampnom);
Param::Set(Param::fslipspnt, fslip);
diff --git a/src/stm32_sine.cpp b/src/stm32_sine.cpp
index bca9064..874b4ac 100644
--- a/src/stm32_sine.cpp
+++ b/src/stm32_sine.cpp
@@ -126,7 +126,7 @@ static void Ms10Task(void)
if (MOD_RUN == opmode && initWait == -1)
{
- PwmGeneration::SetTorquePercent(FP_FROMFLT(torquePercent));
+ PwmGeneration::SetTorquePercent(torquePercent);
}
else if ((MOD_BOOST == opmode || MOD_BUCK == opmode) && initWait == -1)
{
diff --git a/src/temp_meas.cpp b/src/temp_meas.cpp
index d59a713..5ed1b71 100644
--- a/src/temp_meas.cpp
+++ b/src/temp_meas.cpp
@@ -23,13 +23,14 @@
#include
#define TABLEN(a) sizeof(a) / sizeof(a[0])
+#define FIRST_MOTOR_SENSOR TEMP_KTY83
enum coeff { PTC, NTC };
typedef struct TempSensor
{
- int tempMin;
- int tempMax;
+ int16_t tempMin;
+ int16_t tempMax;
uint8_t step;
uint8_t tabSize;
enum coeff coeff;
@@ -90,32 +91,36 @@ static const uint16_t NtcK45[] = { NTCK45 };
/* Temp sensor for outlander front motor (47k) in series with 1.2k with a 2.2k for R2 */
static const uint16_t OutlanderFront[] = { OUTLANDERFRONT };
+/* EPCOS B57861-S 103-F40 temp sensor */
+static const uint16_t epcosb57861[] = { EPCOSB57861 };
+
static const TEMP_SENSOR sensors[] =
{
- { -25, 105, 5, TABLEN(JCurve), NTC, JCurve },
- { 0, 100, 5, TABLEN(Semikron), PTC, Semikron },
- { -5, 100, 5, TABLEN(mbb600), PTC, mbb600 },
- { -50, 150, 10, TABLEN(Kty81hs), NTC, Kty81hs },
- { -50, 150, 10, TABLEN(Pt1000), PTC, Pt1000 },
- { -50, 150, 5, TABLEN(NtcK45), NTC, NtcK45 },
- { -10, 100, 10, TABLEN(leafhs), NTC, leafhs },
- { -25, 105, 5, TABLEN(fs800), PTC, fs800 },
- { -50, 170, 10, TABLEN(Kty83), PTC, Kty83 },
- { -40, 300, 10, TABLEN(Kty84), PTC, Kty84 },
- { -20, 150, 10, TABLEN(leaf), NTC, leaf },
- { -50, 150, 10, TABLEN(kty81m), PTC, kty81m },
- { -20, 200, 5, TABLEN(Toyota), PTC, Toyota },
- { -20, 190, 5, TABLEN(Tesla100k), PTC, Tesla100k },
- { 0, 100, 10, TABLEN(Tesla52k), PTC, Tesla52k },
- { 5, 100, 5, TABLEN(TeslaFluid),PTC, TeslaFluid },
- { -20, 190, 5, TABLEN(Tesla10k), PTC, Tesla10k },
- { -40, 300, 10, TABLEN(OutlanderFront), NTC, OutlanderFront },
+ { -25, 105, 5, TABLEN(JCurve), NTC, JCurve },
+ { 0, 100, 5, TABLEN(Semikron), PTC, Semikron },
+ { -5, 100, 5, TABLEN(mbb600), PTC, mbb600 },
+ { -50, 150, 10, TABLEN(Kty81hs), NTC, Kty81hs },
+ { -50, 150, 10, TABLEN(Pt1000), PTC, Pt1000 },
+ { -50, 150, 5, TABLEN(NtcK45), NTC, NtcK45 },
+ { -10, 100, 10, TABLEN(leafhs), NTC, leafhs },
+ { -25, 105, 5, TABLEN(fs800), PTC, fs800 },
+ { -50, 170, 10, TABLEN(Kty83), PTC, Kty83 },
+ { -40, 300, 10, TABLEN(Kty84), PTC, Kty84 },
+ { -20, 150, 10, TABLEN(leaf), NTC, leaf },
+ { -50, 150, 10, TABLEN(kty81m), PTC, kty81m },
+ { -20, 200, 5, TABLEN(Toyota), PTC, Toyota },
+ { -20, 190, 5, TABLEN(Tesla100k), PTC, Tesla100k },
+ { 0, 100, 10, TABLEN(Tesla52k), PTC, Tesla52k },
+ { 5, 100, 5, TABLEN(TeslaFluid), PTC, TeslaFluid },
+ { -20, 190, 5, TABLEN(Tesla10k), PTC, Tesla10k },
+ { -40, 300, 10, TABLEN(OutlanderFront), NTC, OutlanderFront },
+ { -50, 150, 10, TABLEN(epcosb57861), NTC, epcosb57861},
};
float TempMeas::Lookup(int digit, Sensors sensorId)
{
if (sensorId >= TEMP_LAST) return 0;
- int index = sensorId >= TEMP_KTY83 ? sensorId - TEMP_KTY83 + NUM_HS_SENSORS : sensorId;
+ int index = sensorId >= FIRST_MOTOR_SENSOR ? sensorId - FIRST_MOTOR_SENSOR + NUM_HS_SENSORS : sensorId;
const TEMP_SENSOR * sensor = &sensors[index];
uint16_t last;
@@ -129,7 +134,9 @@ float TempMeas::Lookup(int digit, Sensors sensorId)
if (0 == i) return sensor->tempMin;
float a = sensor->coeff == NTC?cur - digit:digit - cur;
float b = sensor->coeff == NTC?cur - last:last - cur;
- return sensor->step * i + sensor->tempMin - sensor->step * a / b;
+ float c = sensor->step * a / b;
+ float d = (int)(sensor->step * i) + sensor->tempMin;
+ return d - c;
}
last = cur;
}
diff --git a/src/throttle.cpp b/src/throttle.cpp
index df5a632..7f54461 100644
--- a/src/throttle.cpp
+++ b/src/throttle.cpp
@@ -74,6 +74,7 @@ bool Throttle::CheckAndLimitRange(int* potval, int potIdx)
float Throttle::DigitsToPercent(int potval, int potidx)
{
if (potidx > 1) return 0;
+ if (potmax[potidx] == potmin[potidx]) return 100.0f;
return (100 * (potval - potmin[potidx])) / (potmax[potidx] - potmin[potidx]);
}
@@ -83,7 +84,7 @@ float Throttle::CalcThrottle(float potnom, float pot2nom, bool brkpedal)
float scaledBrkMax = brkpedal ? brknompedal : brkmax;
//Never reach 0, because that can spin up the motor
- scaledBrkMax = -1 + (scaledBrkMax * pot2nom) / 100;
+ scaledBrkMax = -0.1 + (scaledBrkMax * pot2nom) / 100.0f;
if (brkpedal)
{