From 9527823a0233a0c21b6246117b50182065c4ac5b Mon Sep 17 00:00:00 2001 From: jsphuebner Date: Sat, 25 Sep 2021 00:25:37 +0200 Subject: [PATCH] Support precharge during bootloader Remove heatcurrent code Do not disable PWM in neutral gear --- include/hwinit.h | 2 +- include/param_prj.h | 6 +++--- libopeninv | 2 +- src/hwinit.cpp | 4 ++-- src/pwmgeneration-foc.cpp | 34 +++------------------------------- src/stm32_sine.cpp | 5 ++++- 6 files changed, 14 insertions(+), 39 deletions(-) diff --git a/include/hwinit.h b/include/hwinit.h index 96e5bfa..9066ea7 100644 --- a/include/hwinit.h +++ b/include/hwinit.h @@ -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); diff --git a/include/param_prj.h b/include/param_prj.h index 8cb7a4a..7839f57 100644 --- a/include/param_prj.h +++ b/include/param_prj.h @@ -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 ) \ @@ -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 ) \ @@ -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 \ diff --git a/libopeninv b/libopeninv index 866a946..9dbc313 160000 --- a/libopeninv +++ b/libopeninv @@ -1 +1 @@ -Subproject commit 866a94612409d3fe5a8e2603342e3315c712c8c9 +Subproject commit 9dbc313824b43e3ce262b18dd1f4abd82dad5f86 diff --git a/src/hwinit.cpp b/src/hwinit.cpp index 0057cea..9c2e6e2 100644 --- a/src/hwinit.cpp +++ b/src/hwinit.cpp @@ -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; @@ -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) { diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp index 5bc8a15..0472286 100644 --- a/src/pwmgeneration-foc.cpp +++ b/src/pwmgeneration-foc.cpp @@ -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(); @@ -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) { @@ -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)); diff --git a/src/stm32_sine.cpp b/src/stm32_sine.cpp index 82b2c60..bca9064 100644 --- a/src/stm32_sine.cpp +++ b/src/stm32_sine.cpp @@ -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; @@ -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(); @@ -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();