diff --git a/lambda-test/avrjunit.c b/lambda-test/avrjunit.c index dd3e11a..ee80b64 100644 --- a/lambda-test/avrjunit.c +++ b/lambda-test/avrjunit.c @@ -9,16 +9,18 @@ #include "USART.h" #include "avrjunit.h" -void runTests(char* suite, char* class, test tests[], uint16_t count) { +void runTests(char* suite, test tests[], uint16_t count) { printString("\n"); char tsbuf[128]; - snprintf(tsbuf, sizeof(tsbuf), "\n", suite, count); + snprintf(tsbuf, sizeof(tsbuf), "\n", + suite, count); printString(tsbuf); for (uint16_t i = 0; i < count; i++) { int result = (*tests[i].test)(); char tcbuf[128]; - snprintf(tcbuf, sizeof(tcbuf), "\n", class, tests[i].name); + snprintf(tcbuf, sizeof(tcbuf), "\n", + tests[i].class, tests[i].name); printString(tcbuf); if (! result) { // failure diff --git a/lambda-test/avrjunit.h b/lambda-test/avrjunit.h index a201fcc..ca32573 100644 --- a/lambda-test/avrjunit.h +++ b/lambda-test/avrjunit.h @@ -6,21 +6,21 @@ */ /** - * A test case with its name and pointer to the test function, + * A test case with its class, name and pointer to the test function, * which should return true on success and false on failure. */ typedef struct { + char* class; char* name; uint8_t (*test)(void); } test; /** * Runs the test cases in the given array and prints the results - * via USART in JUnit XML format, using the given test suite and - * test class names. The size of the array needs to be passed - * along. + * via USART in JUnit XML format, using the given test suite name. + * The size of the array needs to be passed along. * The printed JUnit XML can be read and written to a file * on the receiving side with a command like: * (stty sane; cat > tests.xml) < /dev/ttyUSB0 */ -void runTests(char* suite, char* class, test tests[], uint16_t count); +void runTests(char* suite, test tests[], uint16_t count); diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index aee211f..850bf24 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -110,17 +110,17 @@ } test tests[] = { - {"testGetVoltage", testGetVoltage}, - {"testAverage", testAverage}, - {"testToLambdaValue", testToLambdaValue}, - {"testToLambdaInter", testToLambdaInter}, - {"testToTempI", testToTempI}, - {"testToTempOValue", testToTempOValue}, - {"testToTempOInter", testToTempOInter}, - {"testLookupLinInterValue", testLookupLinInterValue}, - {"testLookupLinInterInter", testLookupLinInterInter}, - {"testLookupLinInterBelow", testLookupLinInterBelow}, - {"testLookupLinInterAbove", testLookupLinInterAbove} + {"adc", "testGetVoltage", testGetVoltage}, + {"sensors", "testAverage", testAverage}, + {"sensors", "testToLambdaValue", testToLambdaValue}, + {"sensors", "testToLambdaInter", testToLambdaInter}, + {"sensors", "testToTempI", testToTempI}, + {"sensors", "testToTempOValue", testToTempOValue}, + {"sensors", "testToTempOInter", testToTempOInter}, + {"sensors", "testLookupLinInterValue", testLookupLinInterValue}, + {"sensors", "testLookupLinInterInter", testLookupLinInterInter}, + {"sensors", "testLookupLinInterBelow", testLookupLinInterBelow}, + {"sensors", "testLookupLinInterAbove", testLookupLinInterAbove} }; int main(void) { @@ -129,7 +129,7 @@ initUSART(); uint16_t count = sizeof(tests) / sizeof(tests[0]); - runTests("lambda", "sensors", tests, count); + runTests("lambda", tests, count); return 0; } diff --git a/lambda/adc.c b/lambda/adc.c index dd49254..da570ee 100644 --- a/lambda/adc.c +++ b/lambda/adc.c @@ -8,6 +8,13 @@ #include #include +// TODO right place for these definitions? Put in makefile? +// #define AREF_MV 4850 +#define AREF_MV 5000 +#define ADC_OFFSET_MV 7 +// #define TEMPO_OP_OFFSET_MV 441 +#define TEMPO_OP_OFFSET_MV 454 + EMPTY_INTERRUPT(ADC_vect); void setupADC(void) { @@ -22,3 +29,17 @@ ADCSRA |= (1 << ADIE); // enable ADC interrupt sei(); // enable global interrupts } + +int16_t getVoltage(uint8_t port) { + + ADMUX = (0b11110000 & ADMUX) | port; + + uint32_t overValue = 0; + for (uint8_t i = 0; i < 16; i++) { + sleep_mode(); + overValue += ADC; + } + int16_t mV = (((overValue >> 2) * AREF_MV) >> 12) + ADC_OFFSET_MV; + + return mV; +} diff --git a/lambda/adc.h b/lambda/adc.h index 06db268..7fa8742 100644 --- a/lambda/adc.h +++ b/lambda/adc.h @@ -14,3 +14,10 @@ * Sets up sleep mode and enables ADC and global interrupts. */ void setupSleepMode(void); + +/** + * Returns the voltage sampled at the given ADC input port doing + * 16x oversampling and taking in account the calibrated AREF and + * ADC offset voltages. + */ +int16_t getVoltage(uint8_t port); diff --git a/lambda/sensors.c b/lambda/sensors.c index 35c72ab..0cef3ea 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -8,9 +8,8 @@ #include #include #include -#include -#include #include "USART.h" +#include "adc.h" #include "sensors.h" #include "integers.h" @@ -97,20 +96,6 @@ printString(line1); } -int16_t getVoltage(uint8_t port) { - - ADMUX = (0b11110000 & ADMUX) | port; - - uint32_t overValue = 0; - for (uint8_t i = 0; i < 16; i++) { - sleep_mode(); - overValue += ADC; - } - int16_t mV = (((overValue >> 2) * AREF_MV) >> 12) + ADC_OFFSET_MV; - - return mV; -} - int16_t average(int16_t value, int16_t average, uint8_t weight) { return roundUp(value + (average * weight), weight + 1); } diff --git a/lambda/sensors.h b/lambda/sensors.h index 19ce01a..58a7e68 100644 --- a/lambda/sensors.h +++ b/lambda/sensors.h @@ -5,13 +5,6 @@ * Author: dode@luniks.net */ -// TODO right place for these definitions? Put in makefile? -// #define AREF_MV 4850 -#define AREF_MV 5000 -#define ADC_OFFSET_MV 7 -// #define TEMPO_OP_OFFSET_MV 441 -#define TEMPO_OP_OFFSET_MV 454 - #define LEAN "Mager" #define IDEAL "Ideal"; #define RICH "Fett!"; @@ -40,13 +33,6 @@ int16_t lambdaVoltage, int16_t lambda); /** - * Returns the voltage sampled at the given ADC input port doing - * 16x oversampling and taking in account the calibrated AREF and - * ADC offset voltages. - */ -int16_t getVoltage(uint8_t port); - -/** * Creates an exponential moving average of the given value and * average weighted by the given weight. */