diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 410f13f..8aa962f 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -62,14 +62,26 @@ // ADC interrupt enabled assertTrue(bit_is_set(ADCSRA, ADIE)); // PC interrupts enabled - assertTrue(bit_is_set(PCICR, PCIE0)); - assertTrue(bit_is_set(PCMSK0, PB0)); + // assertTrue(bit_is_set(PCICR, PCIE0)); + // assertTrue(bit_is_set(PCMSK0, PB0)); + // enable timer 0 overflow interrupt + assertTrue(bit_is_set(TIMSK0, TOIE0)); // sei(); // enable global interrupts assertTrue(bit_is_set(SREG, SREG_I)); return true; } +bool testInitTimers(void) { + initInterrupts(); + + // timer clock prescaler /64 = 15.625 kHz overflowing every 16.2 ms + uint8_t prescalerBy64 = (1 << CS00) | (1 << CS01); + assertTrue((TCCR0B & prescalerBy64) == prescalerBy64); + + return true; +} + /* Module adc */ bool testSetupADC(void) { @@ -292,6 +304,7 @@ // TODO assertions bool testCycle(void) { + cycle(); return true; } @@ -304,21 +317,28 @@ // TODO assertions bool testUpdate(void) { - // set first display option so display() won't actually log something - // via USART which would break the test result XML - // TODO elegant solution for this and testing display()? - - // measurement meas = {0, 0, 0, 0, 0, 0}; - // update(meas); + measurement meas = {0, 0, 0, 0, 0, 0}; + update(meas); return true; } -// these long function names passed along as strings use a lot of memory +// TODO test display() with no display connected? +bool testDisplay(void) { + measurement meas = {0, 0, 0, 0, 0, 0}; + display(meas, " "); + + return true; +} + + +// TODO these long function names passed along as strings use a lot of memory +// use PROGMEM? test tests[] = { {"interrupts", "testSetupPorts", testSetupPorts}, {"interrupts", "testSetupSleepMode", testSetupSleepMode}, {"interrupts", "testInitInterrupts", testInitInterrupts}, + {"interrupts", "testInitTimers", testInitInterrupts}, {"adc", "testSetupADC", testSetupADC}, {"adc", "testGetVoltage", testGetVoltage}, {"integers", "testDivRoundNearest", testDivRoundNearest}, @@ -345,7 +365,8 @@ {"sensors", "testToInfoRich", testToInfoRich}, {"display", "testCycle", testCycle}, {"display", "testUpdateInitial", testUpdateInitial}, - {"display", "testUpdate", testUpdate} + {"display", "testUpdate", testUpdate}, + {"display", "testDisplay", testDisplay} }; int main(void) { diff --git a/lambda/TODO b/lambda/TODO index 439bafa..8e0c2d8 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -4,6 +4,4 @@ * Functionality - Add beeper and beep when air gate valve should be closed and heating of - oxygen sensor should be switched off (or switch it off automatically?) -- Add pushbutton to enter a menu - - Show min/max measurements of previous/current run? \ No newline at end of file + oxygen sensor should be switched off (or switch it off automatically?) \ No newline at end of file diff --git a/lambda/display.c b/lambda/display.c index 2ee0b08..6f4ff99 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -45,11 +45,11 @@ measMax.lambda = MAX(measMax.lambda, meas.lambda); if (position == MENU_MIN_VALUES) { - display(measMin, " <"); + display(measMin, "|<"); } else if (position == MENU_MAX_VALUES) { - display(measMax, " >"); + display(measMax, ">|"); } else { - display(meas, " "); + display(meas, " "); } } @@ -62,7 +62,7 @@ printString(log); } -void display(measurement meas, char hint[]) { +void display(measurement meas, char* hint) { uint16_t lambdax100 = divRoundNearest(meas.lambda, 10); div_t lambdaT = div(lambdax100, 100); diff --git a/lambda/display.h b/lambda/display.h index 2128f3d..8dcc686 100644 --- a/lambda/display.h +++ b/lambda/display.h @@ -27,6 +27,6 @@ /** * Formats the given measurement values and displays them on an 16x2 LCD. */ -void display(measurement, char[]); +void display(measurement, char*); #endif /* DISPLAY_H_ */ diff --git a/lambda/interrupts.c b/lambda/interrupts.c index 40797f6..8ad80d1 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -14,7 +14,7 @@ // INT0 and INT1 are assigned to the LCD, a bit of a shame PORTB |= (1 << PB0); - // PB1 as output + // PB1 as output (just for testing) DDRB |= (1 << PB1); } diff --git a/lambda/lambda.c b/lambda/lambda.c index e00635d..e81ec84 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -31,17 +31,15 @@ #include "display.h" volatile bool buttonPressed = false; -volatile uint8_t updateCount = 0; -volatile uint8_t logCount = 0; +volatile uint8_t intCount = 0; /** * Called every 16.32 ms. */ ISR(TIMER0_OVF_vect) { - updateCount++; - logCount++; + intCount++; if (bit_is_clear(PINB, PB0) && ! buttonPressed) { - PORTB ^= (1 << PB1); + // PORTB ^= (1 << PB1); cycle(); buttonPressed = true; } else if (bit_is_set(PINB, PB0)) { @@ -64,14 +62,16 @@ // main loop while (1) { - if (updateCount >= 6) { - updateCount = 0; - measurement meas = measure(); // about 50 ms - update(meas); // about 100 ms - if (logCount >= 61) { - logCount = 0; - print(meas); // about 400 ms - } + measurement meas; + if (intCount >= 60) { + intCount = 0; + meas = measure(); + update(meas); + print(meas); + } + if (buttonPressed) { + // update display immediately + update(meas); } }