diff --git a/lambda-test/.cproject b/lambda-test/.cproject index 7e18fec..eb7663a 100644 --- a/lambda-test/.cproject +++ b/lambda-test/.cproject @@ -25,7 +25,6 @@ diff --git a/lambda/airgate.c b/lambda/airgate.c index 14bb445..c00a70a 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -17,8 +17,6 @@ #include "interrupts.h" #include "pins.h" -static const uint16_t SPEED_PROD = (uint16_t)MIN_SPEED * MAX_SPEED; - /* Direction */ static volatile int8_t dir = 0; /* Current position */ @@ -30,7 +28,7 @@ /* Acceleration profile ramp */ static volatile uint16_t ramp = 0; /* Speed */ -static volatile uint8_t speed = MIN_SPEED; +static volatile uint16_t speed = MIN_SPEED; /** * Sets increased current for higher torque, sets the direction and initial @@ -92,7 +90,7 @@ } void setAirgate(uint8_t const target) { - if (target == getAirgate() || isAirgateBusy()) { + if (target == getAirgate() || isAirgateBusy() || isDriverFault()) { return; } if (bit_is_clear(PORT, PIN_SLEEP)) { @@ -119,6 +117,10 @@ return steps_c > 0; } +bool isDriverFault(void) { + return bit_is_clear(PORT, PIN_FAULT); +} + void setSleepMode(bool const on) { if (on) { PORT &= ~(1 << PIN_SLEEP); diff --git a/lambda/airgate.h b/lambda/airgate.h index 7a1059d..c8e174f 100644 --- a/lambda/airgate.h +++ b/lambda/airgate.h @@ -12,9 +12,11 @@ #define AIRGATE_H_ /** Min value 1 */ -#define MIN_SPEED 200 +#define MIN_SPEED 200U /** Max value 255 for 8 bit timer and 65535 for 16 bit timer */ -#define MAX_SPEED 250 +#define MAX_SPEED 250U +/** Used to linearize the acceleration curve */ +#define SPEED_PROD (MIN_SPEED * MAX_SPEED) /* * Mapping of airgate position to absolute motor position in (full) steps @@ -55,6 +57,11 @@ bool isAirgateBusy(void); /** + * Returns true if the driver signals fault condition, false otherwise. + */ +bool isDriverFault(void); + +/** * Wakes up the driver or puts it in sleep mode. */ void setSleepMode(bool const on); diff --git a/lambda/messages.h b/lambda/messages.h index 33011af..00e34e2 100644 --- a/lambda/messages.h +++ b/lambda/messages.h @@ -40,6 +40,8 @@ #define MSG_HEATER_OFF_0 "Oxygen sensor" #define MSG_HEATER_OFF_1 "off" #define MSG_HEATER_CURRENT "Heater current" + #define MSG_DRIVER_FAULT_0 "Airgate motor" + #define MSG_DRIVER_FAULT_1 "driver fault!" #define MSG_TIME_SINCE_START "Time since start" #elif LANG == 1 @@ -70,6 +72,8 @@ #define MSG_HEATER_OFF_0 "Lambdasonde" #define MSG_HEATER_OFF_1 "aus" #define MSG_HEATER_CURRENT "Heizstrom" + #define MSG_DRIVER_FAULT_0 "Luftschieber-" + #define MSG_DRIVER_FAULT_1 "antrieb Fehler!" #define MSG_TIME_SINCE_START "Zeit seit Start" #endif diff --git a/lambda/rules.c b/lambda/rules.c index a019959..cb695ad 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -225,18 +225,29 @@ } /** - * Heater rules applied to each not averaged measured heater current value. + * Notifies that the stepper motor driver signals fault condition. */ -Rule heaterRules[] = { +static void driverFault(bool* const fired, Measurement const meas) { + if (isDriverFault()) { + alert_P(BEEPS, LENGTH, TONE, PSTR(MSG_DRIVER_FAULT_0), + PSTR(MSG_DRIVER_FAULT_1), true); + } +} + +/** + * Rules applied to each measurement. + */ +Rule fastRules[] = { {false, heaterReady}, {false, heaterFault}, - {false, heaterTimeout} + {false, heaterTimeout}, + {false, driverFault} }; /** * Rules applied to every nth averaged measurement. */ -Rule rules[] = { +Rule slowRules[] = { {false, airgate50}, {false, airgate25}, {false, airgateClose}, @@ -256,8 +267,8 @@ tempIMax = MAX(tempIMax, meas.tempI); // rules applied at each measurement - for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { - heaterRules[i].cond(&(heaterRules[i].fired), meas); + for (size_t i = 0; i < ARRAY_LENGTH(fastRules); i++) { + fastRules[i].cond(&(fastRules[i].fired), meas); } // evaluation of the fire state and rules applied @@ -265,8 +276,8 @@ if (measCount == MEAS_INT) { measCount = 0; - for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { - rules[i].cond(&(rules[i].fired), meas); + for (size_t i = 0; i < ARRAY_LENGTH(slowRules); i++) { + slowRules[i].cond(&(slowRules[i].fired), meas); } // difference between current and previous temperature @@ -299,13 +310,13 @@ state = undefined; } - for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { - rules[i].fired = false; + for (size_t i = 0; i < ARRAY_LENGTH(slowRules); i++) { + slowRules[i].fired = false; } // default for warmStart should be true - rules[6].fired = true; + slowRules[6].fired = true; - for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { - heaterRules[i].fired = false; + for (size_t i = 0; i < ARRAY_LENGTH(fastRules); i++) { + fastRules[i].fired = false; } }