Skip to content

Commit

Permalink
Merge branch 'float'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Aug 24, 2021
2 parents 8544642 + 0afd8c9 commit 521c898
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 211 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CPPFLAGS = -Os -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/inc
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
LDSCRIPT = stm32_sine.ld
LDFLAGS = -Llibopencm3/lib -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections,-Map,linker.map
LDFLAGS = -Llibopencm3/lib -T$(LDSCRIPT) -march=armv7 -nostartfiles -Wl,--gc-sections,-Map,linker.map
OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.o \
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
temp_meas.o param_save.o throttle.o errormessage.o stm32_can.o pwmgeneration.o \
Expand Down
10 changes: 6 additions & 4 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 5.06.R
#define VER 5.10.R

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
2. Temporary parameters (id = 0)
3. Display values
*/
//Next param id (increase when adding new parameter!): 133
//Next param id (increase when adding new parameter!): 135
//Next value Id: 2049
/* category name unit min max default id */

Expand All @@ -42,6 +42,7 @@
#define MOTOR_PARAMETERS_SINE \
PARAM_ENTRY(CAT_MOTOR, boost, "dig", 0, 37813, 1700, 1 ) \
PARAM_ENTRY(CAT_MOTOR, fweak, "Hz", 0, 1000, 90, 2 ) \
PARAM_ENTRY(CAT_MOTOR, fweakstrt, "Hz", 0, 1000, 400, 129 ) \
PARAM_ENTRY(CAT_MOTOR, fconst, "Hz", 0, 1000, 180, 99 ) \
PARAM_ENTRY(CAT_MOTOR, udcnom, "V", 0, 1000, 0, 78 ) \
PARAM_ENTRY(CAT_MOTOR, fslipmin, "Hz", 0.3, 10, 1, 37 ) \
Expand All @@ -53,7 +54,8 @@
PARAM_ENTRY(CAT_MOTOR, curki, "", 0, 100000, 20000, 108 ) \
PARAM_ENTRY(CAT_MOTOR, curkifrqgain,"dig/Hz", 0, 1000, 50, 120 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp, "", -10000, 0, -100, 118 ) \
PARAM_ENTRY(CAT_MOTOR, syncofs, "dig", 0, 65535, 0, 70 )
PARAM_ENTRY(CAT_MOTOR, syncofs, "dig", 0, 65535, 0, 70 ) \
PARAM_ENTRY(CAT_MOTOR, syncadv, "dig/Hz", 0, 65535, 10, 133 )

#define INVERTER_PARAMETERS_COMMON \
PARAM_ENTRY(CAT_INVERTER,pwmfrq, PWMFRQS, 0, 2, 1, 13 ) \
Expand Down Expand Up @@ -138,7 +140,7 @@
PARAM_ENTRY(CAT_PWM, pwmofs, "dig", -65535, 65535, 0, 41 ) \
PARAM_ENTRY(CAT_COMM, canspeed, CANSPEEDS, 0, 3, 1, 83 ) \
PARAM_ENTRY(CAT_COMM, canperiod, CANPERIODS,0, 1, 0, 88 ) \
PARAM_ENTRY(CAT_COMM, nodeid, "", 1, 63, 1, 129 ) \
PARAM_ENTRY(CAT_COMM, nodeid, "", 1, 63, 1, 134 ) \

#define VALUE_BLOCK1 \
VALUE_ENTRY(version, VERSTR, 2039 ) \
Expand Down
2 changes: 1 addition & 1 deletion include/temp_meas.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TempMeas
TEMP_LAST
};

static s32fp Lookup(int digit, Sensors sensorId);
static float Lookup(int digit, Sensors sensorId);
};


Expand Down
58 changes: 29 additions & 29 deletions include/throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,47 @@ class Throttle
{
public:
static bool CheckAndLimitRange(int* potval, int potIdx);
static s32fp DigitsToPercent(int potval, int potidx);
static s32fp CalcThrottle(s32fp potval, s32fp pot2val, bool brkpedal);
static s32fp CalcIdleSpeed(int speed);
static s32fp CalcCruiseSpeed(int speed);
static bool TemperatureDerate(s32fp tmp, s32fp tmpMax, s32fp& finalSpnt);
static void BmsLimitCommand(s32fp& finalSpnt, bool dinbms);
static void UdcLimitCommand(s32fp& finalSpnt, s32fp udc);
static void IdcLimitCommand(s32fp& finalSpnt, s32fp idc);
static void FrequencyLimitCommand(s32fp& finalSpnt, s32fp frequency);
static s32fp RampThrottle(s32fp finalSpnt);
static float DigitsToPercent(int potval, int potidx);
static float CalcThrottle(float potval, float pot2val, bool brkpedal);
static float CalcIdleSpeed(int speed);
static float CalcCruiseSpeed(int speed);
static bool TemperatureDerate(float tmp, float tmpMax, float& finalSpnt);
static void BmsLimitCommand(float& finalSpnt, bool dinbms);
static void UdcLimitCommand(float& finalSpnt, float udc);
static void IdcLimitCommand(float& finalSpnt, float idc);
static void FrequencyLimitCommand(float& finalSpnt, float frequency);
static float RampThrottle(float finalSpnt);
static int potmin[2];
static int potmax[2];
static s32fp brknom;
static s32fp brknompedal;
static s32fp brkmax;
static s32fp brkcruise;
static s32fp throtmax;
static s32fp throtmin;
static float brknom;
static float brknompedal;
static float brkmax;
static float brkcruise;
static float throtmax;
static float throtmin;
static int idleSpeed;
static int cruiseSpeed;
static s32fp speedkp;
static float speedkp;
static int speedflt;
static s32fp idleThrotLim;
static s32fp regenRamp;
static s32fp throttleRamp;
static float idleThrotLim;
static float regenRamp;
static float throttleRamp;
static int bmslimhigh;
static int bmslimlow;
static int accelmax;
static int accelflt;
static s32fp udcmin;
static s32fp udcmax;
static s32fp idcmin;
static s32fp idcmax;
static s32fp idckp;
static s32fp fmax;
static float udcmin;
static float udcmax;
static float idcmin;
static float idcmax;
static float idckp;
static float fmax;

private:
static int speedFiltered;
static s32fp potnomFiltered;
static s32fp brkRamped;
static s32fp throttleRamped;
static float potnomFiltered;
static float brkRamped;
static float throttleRamped;
};

#endif // THROTTLE_H
10 changes: 5 additions & 5 deletions include/vehiclecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class VehicleControl
static void SelectDirection();
static void GetDigInputs();
static void CalcAndOutputTemp();
static s32fp ProcessUdc();
static s32fp ProcessThrottle();
static float ProcessUdc();
static float ProcessThrottle();
static void SetContactorsOffState();

private:
Expand All @@ -48,9 +48,9 @@ class VehicleControl
static uint16_t bmwAdcNextChan;
static uint16_t bmwAdcValues[4];

static void GetTemps(s32fp& tmphs, s32fp &tmpm);
static s32fp GetUserThrottleCommand();
static void GetCruiseCreepCommand(s32fp& finalSpnt, s32fp throtSpnt);
static void GetTemps(float& tmphs, float &tmpm);
static float GetUserThrottleCommand();
static void GetCruiseCreepCommand(float& finalSpnt, float throtSpnt);
static void BmwAdcAcquire();
};

Expand Down
4 changes: 2 additions & 2 deletions src/hwinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ HWREV detect_hw()
return HW_BLUEPILL;
/*else if (is_floating(GPIOC, GPIO1))
return HW_PRIUSMG1;*/
else if (gpio_get(GPIOB, GPIO1)) //On Tesla M3 board precharge output is tied to Vcc
return HW_TESLAM3;
//else if (gpio_get(GPIOB, GPIO1)) //On Tesla M3 board precharge output is tied to Vcc
// return HW_TESLAM3;
else if (is_floating(GPIOC, GPIO9)) //Desat pin is floating
return HW_REV1;
else if (is_floating(GPIOB, GPIO5)) //Cruise pin is floating
Expand Down
18 changes: 9 additions & 9 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void PwmGeneration::Run()
{
s32fp fwIdRef = idref <= 0 ? fwController.RunProportionalOnly(iq) : 0;
dController.SetRef(idref + fwIdRef);
Param::SetFlt(Param::ifw, fwIdRef);
Param::SetFixed(Param::ifw, fwIdRef);
}
else if (opmode == MOD_MANUAL)
{
Expand All @@ -90,9 +90,9 @@ void PwmGeneration::Run()
idc = FP_MUL(idc, dcCurFac);
idcFiltered = IIRFILTER(idcFiltered, idc, Param::GetInt(Param::idcflt));

Param::SetFlt(Param::fstat, frq);
Param::SetFlt(Param::angle, DIGIT_TO_DEGREE(angle));
Param::SetFlt(Param::idc, idcFiltered);
Param::SetFixed(Param::fstat, frq);
Param::SetFixed(Param::angle, DIGIT_TO_DEGREE(angle));
Param::SetFixed(Param::idc, idcFiltered);
Param::SetInt(Param::uq, uq);
Param::SetInt(Param::ud, ud);

Expand Down Expand Up @@ -246,10 +246,10 @@ s32fp PwmGeneration::ProcessCurrents(s32fp& id, s32fp& iq)
id = FOC::id;
iq = FOC::iq;

Param::SetFlt(Param::id, FOC::id);
Param::SetFlt(Param::iq, FOC::iq);
Param::SetFlt(Param::il1, il1);
Param::SetFlt(Param::il2, il2);
Param::SetFixed(Param::id, FOC::id);
Param::SetFixed(Param::iq, FOC::iq);
Param::SetFixed(Param::il1, il1);
Param::SetFixed(Param::il2, il2);

return 0;
}
Expand All @@ -260,7 +260,7 @@ void PwmGeneration::CalcNextAngleSync(int dir)
{
uint16_t syncOfs = Param::GetInt(Param::syncofs);
uint16_t rotorAngle = Encoder::GetRotorAngle();
int syncadv = (frq - FP_FROMINT(20)) * 10;
int syncadv = (frq - FP_FROMINT(20)) * Param::GetInt(Param::syncadv);
syncadv = MAX(0, syncadv);

//Compensate rotor movement that happened between sampling and processing
Expand Down
16 changes: 8 additions & 8 deletions src/pwmgeneration-sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void PwmGeneration::Run()

SineCore::SetAmp(amp);
Param::SetInt(Param::amp, amp);
Param::SetFlt(Param::fstat, frq);
Param::SetFlt(Param::angle, DIGIT_TO_DEGREE(angle));
Param::SetFixed(Param::fstat, frq);
Param::SetFixed(Param::angle, DIGIT_TO_DEGREE(angle));
SineCore::Calc(angle);

/* Shut down PWM on zero voltage request */
Expand Down Expand Up @@ -246,27 +246,27 @@ s32fp PwmGeneration::ProcessCurrents()

if (edge != NoEdge)
{
Param::SetFlt(Param::il1rms, rms);
Param::SetFixed(Param::il1rms, rms);

if (opmode != MOD_BOOST || opmode != MOD_BUCK)
{
//rough approximation as we do not take power factor into account
s32fp idc = (SineCore::GetAmp() * rms) / SineCore::MAXAMP;
idc = FP_DIV(idc, FP_FROMFLT(1.2247)); //divide by sqrt(3)/sqrt(2)
idc *= fslip < 0 ? -1 : 1;
Param::SetFlt(Param::idc, idc);
Param::SetFixed(Param::idc, idc);
}
}
if (CalcRms(il2, lastEdge[1], currentMax[1], rms, samples[1], il2PrevRms))
{
Param::SetFlt(Param::il2rms, rms);
Param::SetFixed(Param::il2rms, rms);
}

s32fp ilMax = sign * GetIlMax(il1, il2);

Param::SetFlt(Param::il1, il1);
Param::SetFlt(Param::il2, il2);
Param::SetFlt(Param::ilmax, ilMax);
Param::SetFixed(Param::il1, il1);
Param::SetFixed(Param::il2, il2);
Param::SetFixed(Param::ilmax, ilMax);

return ilMax;
}
8 changes: 4 additions & 4 deletions src/pwmgeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ void PwmGeneration::Charge()
int dc = chargeController.Run(iFlt);

if (opmode == MOD_BOOST)
Param::SetFlt(Param::idc, FP_MUL((FP_FROMINT(100) - ampnom), iFlt) / 100);
Param::SetFixed(Param::idc, FP_MUL((FP_FROMINT(100) - ampnom), iFlt) / 100);
else
Param::SetFlt(Param::idc, iFlt);
Param::SetFixed(Param::idc, iFlt);

Param::SetInt(Param::amp, dc);
Param::SetFlt(Param::il1, il1);
Param::SetFlt(Param::il2, il2);
Param::SetFixed(Param::il1, il1);
Param::SetFixed(Param::il2, il2);

timer_set_oc_value(PWM_TIMER, TIM_OC2, dc);
}
Expand Down
Loading

0 comments on commit 521c898

Please sign in to comment.