Skip to content

Commit

Permalink
Support precharge during bootloader
Browse files Browse the repository at this point in the history
Remove heatcurrent code
Do not disable PWM in neutral gear
  • Loading branch information
jsphuebner committed Sep 24, 2021
1 parent 521c898 commit 9527823
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 39 deletions.
2 changes: 1 addition & 1 deletion include/hwinit.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void rtc_setup(void);
void tim_setup(void);
void spi_setup(void);
HWREV detect_hw(void);
void write_bootloader_pininit();
void write_bootloader_pininit(bool bootprec);
HWREV io_setup();
uint16_t pwmio_setup(bool activeLow);

Expand Down
6 changes: 3 additions & 3 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +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, fweakstrt, "Hz", 0, 1000, 400, 134 ) \
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 Down Expand Up @@ -135,12 +135,13 @@
PARAM_ENTRY(CAT_CONTACT, udcsw, "V", 0, 1000, 330, 20 ) \
PARAM_ENTRY(CAT_CONTACT, udcswbuck, "V", 0, 1000, 540, 80 ) \
PARAM_ENTRY(CAT_CONTACT, tripmode, TRIPMODES, 0, 3, 0, 86 ) \
PARAM_ENTRY(CAT_CONTACT, bootprec, ONOFF, 0, 1, 0, 135 ) \
PARAM_ENTRY(CAT_PWM, pwmfunc, PWMFUNCS, 0, 3, 0, 58 ) \
PARAM_ENTRY(CAT_PWM, pwmgain, "", -100000,100000, 100, 40 ) \
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, 134 ) \
PARAM_ENTRY(CAT_COMM, nodeid, "", 1, 63, 1, 129 ) \

#define VALUE_BLOCK1 \
VALUE_ENTRY(version, VERSTR, 2039 ) \
Expand Down Expand Up @@ -195,7 +196,6 @@
VALUE_ENTRY(ifw, "A", 2048 ) \
VALUE_ENTRY(ud, "dig", 2046 ) \
VALUE_ENTRY(uq, "dig", 2047 ) \
VALUE_ENTRY(heatcur, "A", 2043 ) \

#if CONTROL == CTRL_SINE
#define PARAM_LIST \
Expand Down
2 changes: 1 addition & 1 deletion libopeninv
Submodule libopeninv updated 1 files
+10 −13 src/stm32_can.cpp
4 changes: 2 additions & 2 deletions src/hwinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ uint16_t pwmio_setup(bool activeLow)
return actualPattern;
}

void write_bootloader_pininit()
void write_bootloader_pininit(bool bootprec)
{
uint32_t flashSize = desig_get_flash_size();
uint32_t pindefAddr = FLASH_BASE + flashSize * 1024 - PINDEF_BLKNUM * PINDEF_BLKSIZE;
Expand All @@ -196,7 +196,7 @@ void write_bootloader_pininit()
commands.pindef[0].level = 0;
commands.pindef[1].port = GPIOB;
commands.pindef[1].inout = PIN_OUT;
commands.pindef[1].level = 0;
commands.pindef[1].level = bootprec;

if (hwRev == HW_BLUEPILL)
{
Expand Down
34 changes: 3 additions & 31 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void PwmGeneration::Run()
Param::SetInt(Param::uq, uq);
Param::SetInt(Param::ud, ud);

/* Shut down PWM on stopped motor, neutral gear or init phase */
if ((0 == frq && 0 == idref && 0 == qController.GetRef()) || 0 == dir || initwait > 0)
/* Shut down PWM on stopped motor or init phase */
if ((0 == frq && 0 == idref && 0 == qController.GetRef()) || initwait > 0)
{
timer_disable_break_main_output(PWM_TIMER);
dController.ResetIntegrator();
Expand Down Expand Up @@ -129,12 +129,8 @@ void PwmGeneration::Run()

void PwmGeneration::SetTorquePercent(s32fp torquePercent)
{
static int32_t heatCurRamped = 0;
s32fp brkrampstr = Param::Get(Param::brkrampstr);
int direction = Param::GetInt(Param::dir);
int heatCur = Param::GetInt(Param::heatcur);

heatCur = MIN(400, heatCur);

if (frq < brkrampstr && torquePercent < 0)
{
Expand All @@ -149,31 +145,7 @@ void PwmGeneration::SetTorquePercent(s32fp torquePercent)
int32_t is = FP_TOINT(FP_MUL(Param::Get(Param::throtcur), direction * torquePercent));
int32_t id, iq;

if (heatCur > 0 && torquePercent < FP_FROMINT(30))
{
int speed = Param::GetInt(Param::speed);

if (speed == 0 && torquePercent <= 0)
{
iq = 0;
heatCurRamped = RAMPUP(heatCurRamped, heatCur, 10);
id = heatCurRamped;
}
/*else if (torquePercent > 0)
{
id = FP_TOINT((-heatCur * torquePercent) / 30);
}*/
else
{
FOC::Mtpa(is, id, iq);
heatCurRamped = 0;
}
}
else
{
FOC::Mtpa(is, id, iq);
heatCurRamped = 0;
}
FOC::Mtpa(is, id, iq);

qController.SetRef(FP_FROMINT(iq));
fwController.SetRef(FP_FROMINT(iq));
Expand Down
5 changes: 4 additions & 1 deletion src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ extern void parm_Change(Param::PARAM_NUM paramNum)
PwmGeneration::SetAmpnom(Param::Get(Param::ampnom));
break;
#endif
case Param::bootprec:
write_bootloader_pininit(Param::GetBool(Param::bootprec));
break;
case Param::canspeed:
can->SetBaudrate((Can::baudrates)Param::GetInt(Param::canspeed));
break;
Expand Down Expand Up @@ -362,7 +365,6 @@ extern "C" int main(void)
clock_setup();
rtc_setup();
hwRev = io_setup();
write_bootloader_pininit();
tim_setup();
nvic_setup();
parm_load();
Expand Down Expand Up @@ -393,6 +395,7 @@ extern "C" int main(void)
UpgradeParameters();
parm_Change(Param::PARAM_LAST);
parm_Change(Param::nodeid);
parm_Change(Param::bootprec); //rewrite pininit structure if necessary

while(1)
t.Run();
Expand Down

0 comments on commit 9527823

Please sign in to comment.