diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 8d414f4..a64f83b 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -88,9 +88,9 @@ uint8_t prescalerBy64 = (1 << CS00) | (1 << CS01); assertTrue((TCCR0B & prescalerBy64) == prescalerBy64); - // timer1 CTC mode, TOP OCR1A + // timer1 Clear Timer on Compare Match mode, TOP OCR1A assertTrue(bit_is_set(TCCR1B, WGM12)); - // timer clock prescaler/8 + // timer1 clock prescaler/8 assertTrue(bit_is_set(TCCR1B, CS11)); // toggles PB1 at 7.8 kHz generating a 3.9 kHz beep // assertTrue(OCR1A == 16); @@ -216,14 +216,11 @@ meas = measure(); } - assertTrue(meas.tempIVoltage > 4900); - assertTrue(meas.tempOVoltage > 4900); - assertTrue(meas.lambdaVoltage > 4900); - // verify that temperatures and lambda are calculated correctly - assertTrue(meas.tempI == toTempI(meas.tempIVoltage)); - assertTrue(meas.tempO == toTempO(meas.tempOVoltage)); - assertTrue(meas.lambda == toLambda(meas.lambdaVoltage)); + // for voltages > 4950 and <= 5000 mV + assertTrue(meas.tempI > 990 && meas.tempI <= 1000); + assertTrue(meas.tempO == 400); + assertTrue(meas.lambda == 997); return true; } @@ -327,7 +324,7 @@ // TODO assertions bool testUpdate(void) { - measurement meas = {0, 0, 0, 0, 0, 0}; + measurement meas = {0, 0, 0}; updateMeas(meas); return true; @@ -335,7 +332,7 @@ // TODO test display() with no display connected? bool testDisplay(void) { - measurement meas = {0, 0, 0, 0, 0, 0}; + measurement meas = {0, 0, 0}; displayMeas(meas, " "); return true; diff --git a/lambda/TODO b/lambda/TODO index 350ea4b..e2dc7c5 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -1,5 +1,5 @@ * C -- What do static inline volatile extern in C do? +- What do static inline extern in C do? - Read up on "global" variables and modules - Flexarray? http://en.wikipedia.org/wiki/Sizeof - License? (github) @@ -13,5 +13,4 @@ * Circuit - Look at oxygen sensor voltage with voltmeter/oscilloscope - is the voltage really so unstable? -- Put button and beeper pins in pins.h (watch out with OCR1A) -- Reset min/max measurements when enabling simulation mode \ No newline at end of file +- Put button and beeper pins in pins.h (watch out with OCR1A) \ No newline at end of file diff --git a/lambda/command.c b/lambda/command.c index 4e39579..c3b9214 100644 --- a/lambda/command.c +++ b/lambda/command.c @@ -39,11 +39,13 @@ } if (strcmp(fields[0], "se") == 0) { // simulation enable + resetMeas(); simulation = true; beep(1, 2); } else if (strcmp(fields[0], "sd") == 0) { // simulation disable + resetMeas(); simulation = false; beep(1, 2); } diff --git a/lambda/display.c b/lambda/display.c index 468c540..cc3a3df 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -18,42 +18,49 @@ #include "alert.h" #define MENU_OFF 0 -#define MENU_MIN_VALUES 1 -#define MENU_MAX_VALUES 2 +#define MENU_MAX_VALUES 1 uint8_t position = MENU_OFF; bool updatePending = false; measurement measLatest; -measurement measMin = {0, 20, 0, 20, 0, 1000}; -measurement measMax = {0, 0, 0, 0, 0, 2000}; +measurement measMax = {0, 0, 2000}; void cycleDisplay(void) { - updatePending = true; if (isAlertActive()) { // button pressed during alert cancelAlert(); + updatePending = true; return; } - beep(1, 2); position++; if (position > MENU_MAX_VALUES) { position = MENU_OFF; } + updatePending = true; + beep(1, 2); } void updateMeas(measurement meas) { measLatest = meas; - measMin.tempI = MIN(measMin.tempI, meas.tempI); - measMin.tempO = MIN(measMin.tempO, meas.tempO); - measMin.lambda = MAX(measMin.lambda, meas.lambda); - measMax.tempI = MAX(measMax.tempI, meas.tempI); measMax.tempO = MAX(measMax.tempO, meas.tempO); measMax.lambda = MIN(measMax.lambda, meas.lambda); - updateDisplay(); + updatePending = true; +} + +void resetMeas(void) { + measLatest.tempI = 0; + measLatest.tempO = 0; + measLatest.lambda = 2000; + + measMax.tempI = 0; + measMax.tempO = 0; + measMax.lambda = 2000; + + updatePending = true; } void updateDisplay(void) { @@ -61,10 +68,8 @@ return; } - if (position == MENU_MIN_VALUES) { - displayMeas(measMin, "|<"); - } else if (position == MENU_MAX_VALUES) { - displayMeas(measMax, ">|"); + if (position == MENU_MAX_VALUES) { + displayMeas(measMax, "|>"); } else { displayMeas(measLatest, " "); } @@ -81,9 +86,8 @@ void printMeas(measurement meas) { char log[64]; snprintf(log, sizeof(log), - "Ti %3d C %4u - To %3d C %4u - L %4u %4u\r\n", - meas.tempI, meas.tempIVoltage, meas.tempO, meas.tempOVoltage, - meas.lambda, meas.lambdaVoltage); + "Ti %3d C - To %3d C - L %4u \r\n", + meas.tempI, meas.tempO, meas.lambda); printString(log); } diff --git a/lambda/display.h b/lambda/display.h index 231fb23..c769a19 100644 --- a/lambda/display.h +++ b/lambda/display.h @@ -15,12 +15,17 @@ void cycleDisplay(void); /** - * Updates the measurements, tracks min and max values since last start/reset + * Updates the measurements, tracks max values since last start/reset * and updates the display. */ void updateMeas(measurement); /** + * Resets max measurements to initial values. + */ +void resetMeas(void); + +/** * Updates the display with the selected measurement values. */ void updateDisplay(void); diff --git a/lambda/interrupts.c b/lambda/interrupts.c index 3d95b15..36db7b7 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -108,12 +108,12 @@ void initTimers(void) { // timer in normal mode is default - // timer clock prescaler/64 = 15.625 kHz overflowing every 16 ms + // timer0 clock prescaler/64 = 15.625 kHz overflowing every 16 ms TCCR0B |= (1 << CS01) | (1 << CS00); - // Clear Timer on Compare Match mode, TOP OCR1A + // timer1 Clear Timer on Compare Match mode, TOP OCR1A TCCR1B |= (1 << WGM12); - // timer clock prescaler/8 + // timer1 clock prescaler/8 TCCR1B |= (1 << CS11); // toggles PB1 at 7.8 kHz generating a 3.9 kHz beep // OCR1A = 16; diff --git a/lambda/sensors.c b/lambda/sensors.c index 8ae747e..5bc571b 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -84,13 +84,9 @@ ((lambdaVoltageAvg - 4) >> 3); measurement meas; - meas.tempIVoltage = (tempIVoltageAvg >> 3); - meas.tempOVoltage = (tempOVoltageAvg >> 3); - meas.lambdaVoltage = (lambdaVoltageAvg >> 3); - - meas.tempI = toTempI(meas.tempIVoltage); - meas.tempO = toTempO(meas.tempOVoltage); - meas.lambda = toLambda(meas.lambdaVoltage); + meas.tempI = toTempI(tempIVoltageAvg >> 3); + meas.tempO = toTempO(tempOVoltageAvg >> 3); + meas.lambda = toLambda(lambdaVoltageAvg >> 3); return meas; } diff --git a/lambda/sensors.h b/lambda/sensors.h index 299fa44..7c93e8e 100644 --- a/lambda/sensors.h +++ b/lambda/sensors.h @@ -30,11 +30,8 @@ * Measured values. */ typedef struct { - uint16_t tempIVoltage; int16_t tempI; - uint16_t tempOVoltage; int16_t tempO; - uint16_t lambdaVoltage; int16_t lambda; } measurement;