diff --git a/lambda/TODO b/lambda/TODO index 3b5a2e1..135e3c1 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -14,5 +14,4 @@ - Makefile: LANG = 0 - pins.h LCD pins - interrupts.h TIMER0_COMP_MATCH 122/244 (124/248) -- sensors.h: SHUNT_MILLIOHMS 100 (111) -- rules.c: heaterTimeout(): getTime() >= 10800 \ No newline at end of file +- sensors.h: SHUNT_MILLIOHMS 100 (111) \ No newline at end of file diff --git a/lambda/rules.c b/lambda/rules.c index 6173c5c..d5f5846 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -140,8 +140,8 @@ return; } if (meas.current > milliAmpsShort || meas.current < milliAmpsDisconn || - (getTime() >= 180 && meas.current > milliAmpsReady)) { - // short circuit or disconnected or did not warm up within 3 minutes + (getTime() >= 300 && meas.current > milliAmpsReady)) { + // short circuit or disconnected or did not warm up within 5 minutes setHeaterOn(false); setHeaterState(heaterStateFault); alert_P(BEEPS, LENGTH, TONE, PSTR(MSG_HEATER_FAULT_0), @@ -150,12 +150,12 @@ } /** - * Switches the heater off if it is still on after 3 hours and there does + * Switches the heater off if it is still on after 15 mins and there does * not seem to be a fire. */ static void heaterTimeout(bool* const fired, int8_t const dir, Measurement const meas) { - if (isHeaterOn() && getTime() >= 10800 && meas.tempI < TEMP_AIRGATE_0) { + if (isHeaterOn() && getTime() >= 900 && meas.tempI < TEMP_FIRE_OUT) { setHeaterOn(false); alert_P(3, 5, TONE, PSTR(MSG_HEATER_OFF_0), PSTR(MSG_HEATER_OFF_1), false); @@ -163,6 +163,22 @@ } /** + * Switches the heater on if it is off and not in state fault and it seems + * obvious that there is a fire building up. + */ +static void heaterOn(bool* const fired, int8_t const dir, + Measurement const meas) { + if (isHeaterOn() || getHeaterState() == heaterStateFault) { + return; + } + if (dir != burning_down && meas.tempI > TEMP_AIRGATE_0) { + setHeaterOn(true); + alert_P(3, 5, TONE, PSTR(MSG_HEATER_UP_0), + PSTR(MSG_HEATER_UP_1), false); + } +} + +/** * Rules applied to every nth averaged measurement. */ Rule rules[] = { @@ -180,7 +196,8 @@ Rule heaterRules[] = { {false, heaterReady}, {false, heaterFault}, - {false, heaterTimeout} + {false, heaterTimeout}, + {false, heaterOn} }; int8_t getDir(void) { @@ -217,12 +234,12 @@ if (age >= AGE_MEAS_PREV) { dir = none; if ((meas.tempI - rulesMeasPrev.tempI) >= TEMP_DELTA_UP && - rulesMeasMax.tempI < TEMP_MAX && meas.lambda >= LAMBDA_MAX) { + rulesMeasMax.tempI < TEMP_MIN && meas.lambda >= LAMBDA_MAX) { dir = firing_up; - } else if (meas.tempI > TEMP_AIRGATE_0 && meas.lambda < LAMBDA_MAX) { + } else if (meas.tempI > TEMP_MIN || meas.lambda < LAMBDA_MAX) { dir = burning; } else if ((rulesMeasPrev.tempI - meas.tempI) >= TEMP_DELTA_DOWN && - rulesMeasMax.tempI > TEMP_MAX && meas.lambda >= LAMBDA_MAX) { + rulesMeasMax.tempI > TEMP_MIN && meas.lambda >= LAMBDA_MAX) { dir = burning_down; } else if ((meas.tempI - rulesMeasPrev.tempI) >= TEMP_DELTA_UP) { // it seems wood has been added - reset some measurements and rules @@ -232,7 +249,7 @@ for (size_t i = 0; i < rulesSize; i++) { rules[i].fired = false; } - if (! isHeaterOn()) { + if (! isHeaterOn() && getHeaterState() != heaterStateFault) { setHeaterOn(true); } } diff --git a/lambda/rules.h b/lambda/rules.h index 13ccee5..4b94fea 100644 --- a/lambda/rules.h +++ b/lambda/rules.h @@ -18,7 +18,7 @@ /** Age of previous measurements to compare against */ #define AGE_MEAS_PREV 180 /** Oven reaches at least this temperature when the fire is burning */ -#define TEMP_MAX 800 +#define TEMP_MIN 700 /** Min. increase in temperature during AGE_MEAS_PREV when firing up */ #define TEMP_DELTA_UP 10 /** Min. decrease in temperature during AGE_MEAS_PREV when burning down */ @@ -26,7 +26,7 @@ /** Min. temperature at which to set the air gate to 50% when firing up */ #define TEMP_AIRGATE_50 500 /** Max. temperature at which to set the air gate to 25% when burning down */ -#define TEMP_AIRGATE_25 800 +#define TEMP_AIRGATE_25 700 /** * Max. temperature at which to set the air gate to 0% and to switch off the * oxygen sensor heater when burning down diff --git a/lambda/sensors.c b/lambda/sensors.c index a37c0c9..e140069 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -176,7 +176,7 @@ size_t size = sizeof(linADCTable) / sizeof(linADCTable[0]); int16_t dev = lookupLinInter(mV, linADCTable, size); - return (int32_t)mV - dev; + return (int32_t)mV == 0 ? 0 : mV - dev; } char* toInfo(uint16_t const lambda) { diff --git a/lambda/sensors.h b/lambda/sensors.h index 17b02f6..a4d92c7 100644 --- a/lambda/sensors.h +++ b/lambda/sensors.h @@ -19,7 +19,7 @@ * Oxygen sensor heater current limits at certain states in milliamps. */ typedef enum { - milliAmpsReady = 1400, + milliAmpsReady = 1350, milliAmpsShort = 7500, milliAmpsDisconn = 100 } HeaterMilliAmps;