From e9b942df3183ac34a36c7ec5f3280bcaac993c8f Mon Sep 17 00:00:00 2001 From: Andrey G Date: Tue, 21 Mar 2023 21:20:19 +0300 Subject: [PATCH 1/4] heater_control: hanle no supply state (#219) --- firmware/heater_control.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/firmware/heater_control.cpp b/firmware/heater_control.cpp index 27f414d..f95d123 100644 --- a/firmware/heater_control.cpp +++ b/firmware/heater_control.cpp @@ -194,7 +194,10 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS } break; - case HeaterState::Stopped: break; + case HeaterState::Stopped: + case HeaterState::NoHeaterSupply: + /* nop */ + break; } return s.heaterState; @@ -337,6 +340,8 @@ const char* describeHeaterState(HeaterState state) return "ClosedLoop"; case HeaterState::Stopped: return "Stopped"; + case HeaterState::NoHeaterSupply: + return "NoHeaterSupply"; } return "Unknown"; From e9343db75f1ee84c59de344c7f8b86bd57b88bfc Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Tue, 21 Mar 2023 14:20:48 -0400 Subject: [PATCH 2/4] fail fast (#216) * fail fast * More of bash magic --------- Co-authored-by: rusefillc --- firmware/boards/f0_module/build_wideband.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/boards/f0_module/build_wideband.sh b/firmware/boards/f0_module/build_wideband.sh index 5caa5ec..64c1bb1 100755 --- a/firmware/boards/f0_module/build_wideband.sh +++ b/firmware/boards/f0_module/build_wideband.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -o pipefail # first build the bootloader cd bootloader @@ -31,6 +31,7 @@ arm-none-eabi-objcopy -I binary -O binary --gap-fill 0xFF --pad-to 0x63FC build/ # compute the crc and write that to a file (in binary) crc32 build/wideband_fullsize_nocrc.bin | xxd -r -p - > build/wideband_crc.bin +[ $? -eq 0 ] || { echo "crc32 computation failed"; exit 1; } # Now glue the image and CRC together cat build/wideband_fullsize_nocrc.bin build/wideband_crc.bin > build/wideband_image.bin From 9d4fabeda7b6e81dd07587e9f6477708523e8c1e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 22 Mar 2023 14:59:52 -0700 Subject: [PATCH 3/4] Use temperature thresholds instead of ESR thresholds --- firmware/heater_control.cpp | 53 ++++++++++++++++++++----------------- firmware/wideband_config.h | 13 --------- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/firmware/heater_control.cpp b/firmware/heater_control.cpp index f95d123..26fa94c 100644 --- a/firmware/heater_control.cpp +++ b/firmware/heater_control.cpp @@ -12,36 +12,34 @@ #include "can.h" struct sensorHeaterParams { - uint16_t closedLoopThresholdESR; - uint16_t targetESR; - uint16_t overheatESR; - uint16_t underheatESR; + float targetTemp; + float targetESR; }; static const struct sensorHeaterParams heaterParams49 = { - .closedLoopThresholdESR = LSU49_HEATER_CLOSED_LOOP_THRESHOLD_ESR, - .targetESR = LSU49_HEATER_TARGET_ESR, - .overheatESR = LSU49_HEATER_OVERHEAT_ESR, - .underheatESR = LSU49_HEATER_UNDERHEAT_ESR, - }; + .targetTemp = 780, + .targetESR = 300, +}; + static const struct sensorHeaterParams heaterParams42 = { - .closedLoopThresholdESR = LSU42_HEATER_CLOSED_LOOP_THRESHOLD_ESR, - .targetESR = LSU42_HEATER_TARGET_ESR, - .overheatESR = LSU42_HEATER_OVERHEAT_ESR, - .underheatESR = LSU42_HEATER_UNDERHEAT_ESR, - }; + .targetTemp = 730, + .targetESR = 80, +}; + static const struct sensorHeaterParams heaterParamsAdv = { - //TODO - }; + .targetTemp = 785, + .targetESR = 300, +}; static const sensorHeaterParams *getHeaterParams(SensorType type) { switch (type) { - case SensorType::LSU49: - return &heaterParams49; case SensorType::LSU42: return &heaterParams42; case SensorType::LSUADV: return &heaterParamsAdv; + case SensorType::LSU49: + default: + return &heaterParams49; } } @@ -119,7 +117,7 @@ static struct heater_state state[AFR_CHANNELS] = #endif }; -static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowState, float batteryVoltage, float sensorEsr) +static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowState, float batteryVoltage, float sensorTemp) { bool heaterAllowed = heaterAllowState == HeaterAllow::Allowed; @@ -146,13 +144,17 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS return HeaterState::Preheat; } + float overheatTemp = heater->targetTemp + 100; + float closedLoopTemp = heater->targetTemp - 50; + float underheatTemp = heater->targetTemp - 100; + switch (s.heaterState) { case HeaterState::Preheat: s.timeCounter--; // If preheat timeout, or sensor is already hot (engine running?) - if (s.timeCounter <= 0 || sensorEsr < heater->closedLoopThresholdESR) + if (s.timeCounter <= 0 || sensorTemp > closedLoopTemp) { // If enough time has elapsed, start the ramp // Start the ramp at 4 volts @@ -167,7 +169,7 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS // Stay in preheat - wait for time to elapse break; case HeaterState::WarmupRamp: - if (sensorEsr < heater->closedLoopThresholdESR) + if (sensorTemp > closedLoopTemp) { return HeaterState::ClosedLoop; } @@ -182,12 +184,12 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS break; case HeaterState::ClosedLoop: // Check that the sensor's ESR is acceptable for normal operation - if (sensorEsr < heater->overheatESR) + if (sensorTemp > overheatTemp) { SetFault(s.ch, Fault::SensorOverheat); return HeaterState::Stopped; } - else if (sensorEsr > heater->underheatESR) + else if (sensorTemp < underheatTemp) { SetFault(s.ch, Fault::SensorUnderheat); return HeaterState::Stopped; @@ -223,6 +225,8 @@ static float GetVoltageForState(struct heater_state &s, float heaterEsr) case HeaterState::ClosedLoop: // "nominal" heater voltage is 7.5v, so apply correction around that point (instead of relying on integrator so much) // Negated because lower resistance -> hotter + + // TODO: heater PID should operate on temperature, not ESR return 7.5f - s.heaterPid.GetOutput(heater->targetESR, heaterEsr); case HeaterState::Stopped: // Something has gone wrong, turn off the heater. @@ -256,6 +260,7 @@ static void HeaterThread(void*) // Read sensor state float heaterEsr = GetSensorInternalResistance(s.ch); + float sensorTemperature = GetSensorTemperature(s.ch); // If we haven't heard from rusEFI, use the internally sensed // battery voltage instead of voltage over CAN. @@ -264,7 +269,7 @@ static void HeaterThread(void*) : GetRemoteBatteryVoltage(); // Run the state machine - s.heaterState = GetNextState(s, heaterAllowState, batteryVoltage, heaterEsr); + s.heaterState = GetNextState(s, heaterAllowState, batteryVoltage, sensorTemperature); float heaterVoltage = GetVoltageForState(s, heaterEsr); // Limit to 11 volts diff --git a/firmware/wideband_config.h b/firmware/wideband_config.h index 936d283..60a31c3 100644 --- a/firmware/wideband_config.h +++ b/firmware/wideband_config.h @@ -49,19 +49,6 @@ // mininal battery voltage to continue heating #define HEATER_BATTETY_OFF_VOLTAGE 8.5 -//LSU 4.9 -#define LSU49_HEATER_CLOSED_LOOP_THRESHOLD_ESR 500 -#define LSU49_HEATER_TARGET_ESR 300 -#define LSU49_HEATER_OVERHEAT_ESR 150 -#define LSU49_HEATER_UNDERHEAT_ESR 700 - -//LSU 4.2 -// TODO: check this!!! -#define LSU42_HEATER_CLOSED_LOOP_THRESHOLD_ESR 150 -#define LSU42_HEATER_TARGET_ESR 90 -#define LSU42_HEATER_OVERHEAT_ESR 45 -#define LSU42_HEATER_UNDERHEAT_ESR 250 - // ******************************* // TunerStudio configuration // ******************************* From ebc39b3690b2fc7225e88d8a57f8857425976233 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:59:06 -0400 Subject: [PATCH 4/4] f1_rev3: used MCU has gpio port F and G (in bigger package) (#221) Set safe state for gpio ports F and G to keep compiler happy. Co-authored-by: Andrey Gusakov --- firmware/boards/f1_rev3/board.c | 3 +++ firmware/boards/f1_rev3/board.h | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/firmware/boards/f1_rev3/board.c b/firmware/boards/f1_rev3/board.c index a481eb9..7aae2f5 100644 --- a/firmware/boards/f1_rev3/board.c +++ b/firmware/boards/f1_rev3/board.c @@ -30,6 +30,9 @@ const PALConfig pal_default_config = {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH}, {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH}, {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH}, + /* Following GPIO ports are not balled out on 64 pin package, but still needs to be set to safe state */ + {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH}, + {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH}, }; #endif diff --git a/firmware/boards/f1_rev3/board.h b/firmware/boards/f1_rev3/board.h index ace74c5..ce42d2e 100644 --- a/firmware/boards/f1_rev3/board.h +++ b/firmware/boards/f1_rev3/board.h @@ -146,6 +146,22 @@ #define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */ #define VAL_GPIOEODR 0x0000FFFF +/* + * Port F setup. + * Everything input with pull-up expect: + */ +#define VAL_GPIOFCRL 0x88888888 /* PF7...PF0 */ +#define VAL_GPIOFCRH 0x88888888 /* PF15...PF8 */ +#define VAL_GPIOFODR 0xFFFFFFFF + +/* + * Port G setup. + * Everything input with pull-up expect: + */ +#define VAL_GPIOGCRL 0x88888888 /* PG7...PG0 */ +#define VAL_GPIOGCRH 0x88888888 /* PG15...PG8 */ +#define VAL_GPIOGODR 0xFFFFFFFF + /* * USB bus activation macro, required by the USB driver. */