diff --git a/lambda/Makefile b/lambda/Makefile index 5cc8122..6d6b6b9 100644 --- a/lambda/Makefile +++ b/lambda/Makefile @@ -15,7 +15,7 @@ ## 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 +display.c alert.c ## Here you can link to one more directory (and multiple .c files) EXTRA_SOURCE_DIR = diff --git a/lambda/alert.c b/lambda/alert.c new file mode 100644 index 0000000..3388603 --- /dev/null +++ b/lambda/alert.c @@ -0,0 +1,49 @@ +/* + * alert.c + * + * Created on: 24.04.2015 + * Author: dode@luniks.net + */ + +#include +#include +#include +#include "USART.h" +#include "alert.h" + +uint8_t oscCount = 0; +uint8_t beepCount = 0; +uint8_t beepLength = 0; + +void oscillate(void) { + if (beepCount == 0) { + return; + } + if (oscCount == 0) { + // turn beep on + DDRB |= (1 << PB1); + } + if (oscCount == beepLength) { + // turn beep off + DDRB &= ~(1 << PB1); + beepCount--; + if (beepCount == 0) { + // clear alert + } + } + oscCount == beepLength * 2 ? oscCount = 0 : oscCount++; +} + +void beep(uint8_t beeps, uint8_t length) { + oscCount = 0; + beepCount = beeps; + beepLength = length; +} + +void alert(uint8_t beeps, uint8_t length, char* line0, char* line1) { + oscCount = 0; + beepCount = beeps; + beepLength = length; + // set alert + // set display text +} diff --git a/lambda/alert.h b/lambda/alert.h new file mode 100644 index 0000000..bfae948 --- /dev/null +++ b/lambda/alert.h @@ -0,0 +1,17 @@ +/* + * alert.h + * + * Created on: 24.04.2015 + * Author: dode@luniks.net + */ + +#ifndef ALERT_H_ +#define ALERT_H_ + +void oscillate(void); + +void beep(uint8_t beeps, uint8_t length); + +void alert(uint8_t beeps, uint8_t length, char* line0, char* line1); + +#endif /* ALERT_H_ */ diff --git a/lambda/display.c b/lambda/display.c index 6f4ff99..cdbfa3c 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -38,11 +38,11 @@ void update(measurement meas) { measMin.tempI = MIN(measMin.tempI, meas.tempI); measMin.tempO = MIN(measMin.tempO, meas.tempO); - measMin.lambda = MIN(measMin.lambda, meas.lambda); + measMin.lambda = MAX(measMin.lambda, meas.lambda); measMax.tempI = MAX(measMax.tempI, meas.tempI); measMax.tempO = MAX(measMax.tempO, meas.tempO); - measMax.lambda = MAX(measMax.lambda, meas.lambda); + measMax.lambda = MIN(measMax.lambda, meas.lambda); if (position == MENU_MIN_VALUES) { display(measMin, "|<"); diff --git a/lambda/interrupts.c b/lambda/interrupts.c index 8ad80d1..f2044d5 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -13,9 +13,6 @@ // pull-up resistor for the mouton // INT0 and INT1 are assigned to the LCD, a bit of a shame PORTB |= (1 << PB0); - - // PB1 as output (just for testing) - DDRB |= (1 << PB1); } void setupSleepMode(void) { @@ -26,10 +23,6 @@ // enable ADC interrupt ADCSRA |= (1 << ADIE); - // enable PC interrupts - // PCICR |= (1 << PCIE0); - // PCMSK0 |= (1 << PB0); - // enable timer 0 overflow interrupt TIMSK0 |= (1 << TOIE0); @@ -39,6 +32,15 @@ void initTimers(void) { // timer in normal mode is default - // timer clock prescaler /64 = 15.625 kHz overflowing every 16.2 ms - TCCR0B |= (1 << CS00) | (1 << CS01); + // timer clock prescaler/64 = 15.625 kHz overflowing every 16 ms + TCCR0B |= (1 << CS01) | (1 << CS00); + + // toggle pin PB1 on compare match + TCCR1A |= (1 << COM1A0); + // CTC mode, TOP OCR1A + TCCR1B |= (1 << WGM12); + // timer clock prescaler/8 + TCCR1B |= (1 << CS11); + // toggles PB1 at 3.9 kHz generating a 1.95 kHz beep + OCR1A = 32; } diff --git a/lambda/lambda.c b/lambda/lambda.c index e81ec84..87258d6 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -29,19 +29,21 @@ #include "sensors.h" #include "integers.h" #include "display.h" +#include "alert.h" volatile bool buttonPressed = false; volatile uint8_t intCount = 0; /** - * Called every 16.32 ms. + * Called every 16 ms. */ ISR(TIMER0_OVF_vect) { intCount++; + oscillate(); if (bit_is_clear(PINB, PB0) && ! buttonPressed) { - // PORTB ^= (1 << PB1); - cycle(); buttonPressed = true; + cycle(); + beep(3, 3); } else if (bit_is_set(PINB, PB0)) { buttonPressed = false; } @@ -63,8 +65,9 @@ // main loop while (1) { measurement meas; - if (intCount >= 60) { + if (intCount >= 61) { intCount = 0; + // causes a click in the beep, because of sleep mode? meas = measure(); update(meas); print(meas);