diff --git a/lambda/.gitignore b/lambda/.gitignore index afd821e..0720336 100644 --- a/lambda/.gitignore +++ b/lambda/.gitignore @@ -2,3 +2,4 @@ /Release/ /lambda.elf /lambda.hex +/lambda.lst diff --git a/lambda/TODO b/lambda/TODO index 8e0c2d8..1606b8c 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -3,5 +3,9 @@ - Read up on "global" variables and modules * 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?) \ No newline at end of file +- Add rules and alerts according to FIRE RULEZ! + +* Circuit +- Look at oxygen sensor voltage with voltmeter/oscilloscope - is the voltage + really so unstable? +- Verify ADC voltages against voltmeter with other uC (ADC_OFFSET_MV) \ No newline at end of file diff --git a/lambda/adc.c b/lambda/adc.c index 15b5f9d..f690ac2 100644 --- a/lambda/adc.c +++ b/lambda/adc.c @@ -14,8 +14,7 @@ #include "adc.h" /** - * Sets up a fake ISR to just return to where sleep_mode() was called - * when ADC conversion is complete (ADC_vect). + * Returns to where sleep_mode() was called when ADC conversion is complete. */ EMPTY_INTERRUPT(ADC_vect); @@ -32,7 +31,6 @@ } uint16_t getVoltage(uint8_t pin) { - ADMUX = (0b11110000 & ADMUX) | pin; uint32_t overValue = 0; diff --git a/lambda/alert.c b/lambda/alert.c index 25b31f4..50ce6e8 100644 --- a/lambda/alert.c +++ b/lambda/alert.c @@ -52,6 +52,8 @@ } void cancelAlert(void) { + beepCount = 0; + // turn beep off TCCR1A &= ~(1 << COM1A0); alertActive = false; } diff --git a/lambda/command.c b/lambda/command.c index f617d36..ff97dc1 100644 --- a/lambda/command.c +++ b/lambda/command.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -15,6 +16,7 @@ #include "command.h" bool simulation = false; +bool logging = false; void command(char* data) { char* fields[8]; @@ -24,20 +26,34 @@ fields[index++] = token; token = strtok(NULL, " "); } - if (strcmp(fields[0], "sien") == 0) { + if (strcmp(fields[0], "se") == 0) { + // simulation enable simulation = true; beep(1, 2); } - else if (strcmp(fields[0], "sidi") == 0) { + else if (strcmp(fields[0], "sd") == 0) { + // simulation disable simulation = false; beep(1, 2); } - else if (strcmp(fields[0], "menu") == 0) { + else if (strcmp(fields[0], "le") == 0) { + // logging enable + logging = true; + beep(1, 2); + } + else if (strcmp(fields[0], "ld") == 0) { + // logging disable + logging = false; + beep(1, 2); + } + else if (strcmp(fields[0], "cm") == 0) { + // cycle menu cycleDisplay(); // updateMeas(meas); } - else if (strcmp(fields[0], "tsal") == 0) { - alert(3, 20, "Beep Beep Beep!", fields[1]); + else if (strcmp(fields[0], "ta") == 0) { + // test alert + alert(1, 20, "Beep!", fields[1]); } else if (simulation) { measurement meas = readMeas(fields); @@ -48,3 +64,7 @@ bool isSimulation(void) { return simulation; } + +bool isLogging(void) { + return logging; +} diff --git a/lambda/command.h b/lambda/command.h index 71e0546..7807be0 100644 --- a/lambda/command.h +++ b/lambda/command.h @@ -12,4 +12,6 @@ bool isSimulation(void); +bool isLogging(void); + #endif /* COMMAND_H_ */ diff --git a/lambda/interrupts.c b/lambda/interrupts.c index 76db62d..50f009a 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -19,7 +19,8 @@ } void setupSleepMode(void) { - set_sleep_mode(SLEEP_MODE_ADC); + // SLEEP_MODE_ADC corrupts USART TX/RX data and causes a click in the beep + set_sleep_mode(SLEEP_MODE_IDLE); } void initInterrupts(void) { @@ -43,6 +44,7 @@ // timer clock prescaler/64 = 15.625 kHz overflowing every 16 ms TCCR0B |= (1 << CS01) | (1 << CS00); + // TODO use timer2 which continues running during SLEEP_MODE_ADC? // toggle pin PB1 on compare match // TCCR1A |= (1 << COM1A0); // CTC mode, TOP OCR1A @@ -51,6 +53,6 @@ TCCR1B |= (1 << CS11); // toggles PB1 at 7.8 kHz generating a 3.9 kHz beep // OCR1A = 16; - // less noisy + // less noisy 1.8 kHz OCR1A = 32; } diff --git a/lambda/lambda.c b/lambda/lambda.c index 606df42..4c0ca1c 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include "USART.h" @@ -57,8 +56,6 @@ ISR(USART_RX_vect) { if (bit_is_set(UCSR0A, RXC0) && ! usartReceived) { char data = UDR0; - loop_until_bit_is_set(UCSR0A, UDRE0); - UDR0 = data; if (dataCount < sizeof(usartData) - 1 && data != '\n' && data != '\r') { usartData[dataCount++] = data; } else { @@ -84,15 +81,15 @@ alert(1, 2, " Hello! ", ""); measurement meas; - // memset(&meas, 0, sizeof(meas)); // main loop while (1) { if (intCount >= 62 && ! isSimulation()) { intCount = 0; - // causes a click in the beep, because of sleep mode? meas = measure(); - printMeas(meas); + if (isLogging()) { + printMeas(meas); + } updateMeas(meas); } if (buttonPressed) { diff --git a/lambda/sensors.c b/lambda/sensors.c index 74e1298..4c84c70 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -59,7 +59,7 @@ }; /** - * Variables holding averaged voltages. + * Variables holding averaged voltages*8. */ uint32_t lambdaVoltageAvg = 44 << 3; // Lambda 2.00 uint32_t tempIVoltageAvg = 100 << 3; // 20°C @@ -96,9 +96,9 @@ measurement readMeas(char* fields[]) { measurement meas; - meas.tempI = strtol(fields[0], NULL, 10); - meas.tempO = strtol(fields[1], NULL, 10); - meas.lambda = strtol(fields[2], NULL, 10); + meas.tempI = atoi(fields[0]); + meas.tempO = atoi(fields[1]); + meas.lambda = atoi(fields[2]); return meas; }