From c711252791018d7818e4e717da1e2312ee94928d Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 10 Dec 2020 22:08:00 -0800 Subject: [PATCH] detect sensor overheat --- firmware/fault.h | 1 + firmware/heater_control.cpp | 11 ++++++++--- firmware/wideband_config.h | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/firmware/fault.h b/firmware/fault.h index f5ae19e..7b4967a 100644 --- a/firmware/fault.h +++ b/firmware/fault.h @@ -6,6 +6,7 @@ enum class Fault // First fault code at 3 so it's easier to see SensorDidntHeat = 3, + SensorOverheat = 4, }; void setFault(Fault fault); diff --git a/firmware/heater_control.cpp b/firmware/heater_control.cpp index 2d17bb9..6275603 100644 --- a/firmware/heater_control.cpp +++ b/firmware/heater_control.cpp @@ -20,7 +20,7 @@ enum class HeaterState Stopped, }; -int timeCounter = 5000 / 50; +int timeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD; float rampDuty = 0.5f; static HeaterState GetNextState(HeaterState state, float sensorEsr) @@ -37,7 +37,7 @@ static HeaterState GetNextState(HeaterState state, float sensorEsr) rampDuty = 0.5f; // Next phase times out at 15 seconds - timeCounter = 15000 / 50; + timeCounter = HEATER_WARMUP_TIMEOUT / HEATER_CONTROL_PERIOD; return HeaterState::WarmupRamp; } @@ -45,7 +45,7 @@ static HeaterState GetNextState(HeaterState state, float sensorEsr) // Stay in preheat - wait for time to elapse break; case HeaterState::WarmupRamp: - if (sensorEsr < 1000) + if (sensorEsr < HEATER_CLOSED_LOOP_THRESHOLD_ESR) { return HeaterState::ClosedLoop; } @@ -60,6 +60,11 @@ static HeaterState GetNextState(HeaterState state, float sensorEsr) break; case HeaterState::ClosedLoop: // TODO: handle departure from closed loop + if (sensorEsr < HEATER_FAULT_ESR) + { + setFault(Fault::SensorOverheat); + } + break; case HeaterState::Stopped: break; } diff --git a/firmware/wideband_config.h b/firmware/wideband_config.h index fc1d974..80b1b73 100644 --- a/firmware/wideband_config.h +++ b/firmware/wideband_config.h @@ -32,4 +32,10 @@ // Heater controller config // ******************************* #define HEATER_CONTROL_PERIOD 50 + +#define HEATER_PREHEAT_TIME 5000 +#define HEATER_WARMUP_TIMEOUT 15000 + +#define HEATER_CLOSED_LOOP_THRESHOLD_ESR 1000 #define HEATER_TARGET_ESR 300 +#define HEATER_FAULT_ESR 200