From 8032327cc21aa50c87b58b2f11b4fcfb45f727ec Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Fri, 10 Sep 2010 10:16:35 +0200 Subject: [PATCH] avr: add support for a configurable PULSE_CONST and PULSE_HALF --- mote/v1/avr/Makefile | 7 +++++-- mote/v1/avr/main.c | 29 ++++++++++++++++++----------- mote/v1/avr/main.h | 10 ++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/mote/v1/avr/Makefile b/mote/v1/avr/Makefile index 38a527a..0e28af9 100755 --- a/mote/v1/avr/Makefile +++ b/mote/v1/avr/Makefile @@ -47,17 +47,20 @@ TARGET = main # make PHASE=x METERCONST=y SENSOR0=z ... # DBG = 0 -# +# analog settings TYPE = 2300501 PHASE = 1 METERCONST= 5508 +# pulse settings +PULSE_CONST = 1 +PULSE_HALF = 0 # SENSOR0 = 0123456789abcdef0123456789abcde0 SENSOR1 = 0123456789abcdef0123456789abcde1 SENSOR2 = 0123456789abcdef0123456789abcde2 SENSOR3 = 0123456789abcdef0123456789abcde3 # -CEXTRA = -D DBG=$(DBG) -D PHASE=$(PHASE) -D METERCONST=$(METERCONST) -D 'SENSOR0="$(SENSOR0)"' -D 'SENSOR1="$(SENSOR1)"' -D 'SENSOR2="$(SENSOR2)"' -D 'SENSOR3="$(SENSOR3)"' +CEXTRA = -D DBG=$(DBG) -D PHASE=$(PHASE) -D METERCONST=$(METERCONST) -D PULSE_CONST=$(PULSE_CONST) -D PULSE_HALF=$(PULSE_HALF) -D 'SENSOR0="$(SENSOR0)"' -D 'SENSOR1="$(SENSOR1)"' -D 'SENSOR2="$(SENSOR2)"' -D 'SENSOR3="$(SENSOR3)"' ############################################################################### diff --git a/mote/v1/avr/main.c b/mote/v1/avr/main.c index 75609a8..b5b0be9 100644 --- a/mote/v1/avr/main.c +++ b/mote/v1/avr/main.c @@ -38,7 +38,7 @@ #include // variable declarations -volatile struct state aux[4] = {{false, false, START, 0}, {false, false, START, 0}, {false, false, START, 0}, {false, false, START, 0}}; +volatile struct state aux[4] = {{false, false, false, START, 0}, {false, false, false, START, 0}, {false, false, false, START, 0}, {false, false, false, START, 0}}; volatile struct sensor EEMEM EEPROM_measurements[4] = {{SENSOR0, START}, {SENSOR1, START}, {SENSOR2, START}, {SENSOR3, START}}; volatile struct sensor measurements[4]; @@ -50,16 +50,12 @@ volatile uint16_t timer = 0; // interrupt service routine for INT0 ISR(INT0_vect) { - measurements[2].value++; - aux[2].pulse = true; - aux[2].time = time.ms; + pulse_add(&measurements[2], &aux[2]); } // interrupt service routine for INT1 ISR(INT1_vect) { - measurements[3].value++; - aux[3].pulse = true; - aux[3].time = time.ms; + pulse_add(&measurements[3], &aux[3]); } // interrupt service routine for PCI2 (PCINT20) @@ -69,14 +65,25 @@ ISR(PCINT2_vect) { aux[4].toggle = true; } else { - measurements[4].value++; - aux[4].pulse = true; - aux[4].time = time.ms; - aux[4].toggle = false; + pulse_add(&measurements[4], &aux[4]); } } **/ +void pulse_add(volatile struct sensor *measurement, volatile struct state *aux) { + if (aux->half == true) { + measurement->value += PULSE_CONST + 1; + } + else { + measurement->value += PULSE_CONST; + } +#if PULSE_HALF + aux->half = !aux->half; +#endif + aux->pulse = true; + aux->time = time.ms; +} + // interrupt service routine for ADC ISR(TIMER2_COMPA_vect) { #if DBG > 0 diff --git a/mote/v1/avr/main.h b/mote/v1/avr/main.h index b29dd31..ea0a9e1 100644 --- a/mote/v1/avr/main.h +++ b/mote/v1/avr/main.h @@ -50,6 +50,14 @@ #error "METERCONST not defined" #endif +#ifndef PULSE_CONST + #error "PULSE_CONST not defined" +#endif + +#ifndef PULSE_HALF + #error "PULSE_HALF not defined" +#endif + #define START 0 #define END3 0xffffffff #define END2 0xeeeeeeee @@ -96,6 +104,7 @@ struct time_struct { struct state { boolean pulse; boolean toggle; + boolean half; uint32_t nano; uint16_t adc; @@ -116,4 +125,5 @@ struct sensor { // prototypes void WDT_off(void); void WDT_on(void); +void pulse_add(volatile struct sensor *measurement, volatile struct state *aux); void send(uint8_t msg_type, const struct sensor *measurement, const struct state *aux);