diff --git a/lambda-test/Makefile b/lambda-test/Makefile index 1fc122f..8c8a4da 100644 --- a/lambda-test/Makefile +++ b/lambda-test/Makefile @@ -1,17 +1,17 @@ +# Makefile adopted from the book Make: AVR Programming by Elliot Williams +# https://github.com/hexagon5un/AVR-Programming -##########------------------------------------------------------########## -########## Project-specific Details ########## -########## Check these every time you start a new project ########## -##########------------------------------------------------------########## - -MCU = atmega328p +MCU = atmega328p F_CPU = 1000000 +# Also try BAUD = 19200 or 38400 if you're feeling lucky. BAUD = 9600 -## Also try BAUD = 19200 or 38400 if you're feeling lucky. -## This is where your main() routine lives +# Main function MAIN = lambda-test.c +# en: 0 (default), de: 1 +LANG = 0 + ## If you've split your program into multiple .c / .h files, ## include the additional source (in same directory) here LOCAL_SOURCE = avrjunit.c adc-test.c alert-test.c command-test.c \ diff --git a/lambda/Makefile b/lambda/Makefile index 69df61a..4dd53cb 100644 --- a/lambda/Makefile +++ b/lambda/Makefile @@ -1,26 +1,21 @@ +# Makefile adopted from the book Make: AVR Programming by Elliot Williams +# https://github.com/hexagon5un/AVR-Programming -##########------------------------------------------------------########## -########## Project-specific Details ########## -########## Check these every time you start a new project ########## -##########------------------------------------------------------########## - -MCU = atmega328p +MCU = atmega328p +# Currently supported are 1 MHz and 8 MHz F_CPU = 1000000 +# Also try BAUD = 19200 or 38400 if you're feeling lucky. BAUD = 9600 -## Also try BAUD = 19200 or 38400 if you're feeling lucky. -## This is where your main() routine lives +# Main function MAIN = lambda.c -## en: 0 (default), de: 1 +# en: 0 (default), de: 1 LANG = 0 -## If you've split your program into multiple .c / .h files, -## include the additional source (in same directory) here LOCAL_SOURCE = usart.c interrupts.c adc.c sensors.c integers.c lcdroutines.c \ display.c alert.c command.c strings.c rules.c -## Here you can link to one more directory (and multiple .c files) EXTRA_SOURCE_DIR = EXTRA_SOURCE_FILES = diff --git a/lambda/TODO b/lambda/TODO index 9594df8..3b5a2e1 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -3,9 +3,9 @@ - Flexarray? http://en.wikipedia.org/wiki/Sizeof * AVR -- Take in account F_CPU everywhere CPU speed matters * Functionality +- Handle firing up again without reset * Circuit - AVCC should be connected to VCC via an LC network @@ -13,6 +13,6 @@ * Release/put in Makefile? - Makefile: LANG = 0 - pins.h LCD pins -- interrupts.h: INTS_PER_SEC 61 -- sensors.h: SHUNT_MILLIOHMS 100 +- 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 diff --git a/lambda/rules.c b/lambda/rules.c index c083b08..2219a83 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -22,6 +22,7 @@ static Measurement rulesMeasMax = {0, 0, 2000, 0}; static Measurement rulesMeasPrev = {0, 0, 2000, 0}; +static bool measPrevInit = false; int8_t getDir(void) { return dir; @@ -164,6 +165,8 @@ } // TODO what if fired up again without reset? +// - Rules are in state fired (no reset) and don't fire again +// - Heating is not switched on again if already switched off /** * Rules applied to every nth averaged measurement @@ -206,6 +209,12 @@ age++; + // init previous measurements with current measurements + if (! measPrevInit) { + rulesMeasPrev = meas; + measPrevInit = true; + } + // try to figure out if the fire is building up or burning down by // comparing current measurements with ones that are 3 minutes old. if (age >= 180) { @@ -226,11 +235,7 @@ } void resetRules(void) { - rulesMeasPrev.tempI = 0; - rulesMeasPrev.tempO = 0; - rulesMeasPrev.lambda = 2000; - rulesMeasPrev.current = 0; - + measPrevInit = false; rulesMeasMax.tempI = 0; age = 0;