From e5e352d5cad215f7b1bf48ea6c7bea3c7ad03397 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Sun, 10 Oct 2010 20:06:11 +0200 Subject: [PATCH] avr: make pulse constant and half parameters configurable per input --- mote/v1/avr/Makefile | 11 ++++++++--- mote/v1/avr/main.c | 21 +++++++++++---------- mote/v1/avr/main.h | 26 +++++++++++++++++++++----- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/mote/v1/avr/Makefile b/mote/v1/avr/Makefile index 0e28af9..ec315df 100755 --- a/mote/v1/avr/Makefile +++ b/mote/v1/avr/Makefile @@ -52,15 +52,20 @@ TYPE = 2300501 PHASE = 1 METERCONST= 5508 # pulse settings -PULSE_CONST = 1 -PULSE_HALF = 0 +PULSE_CONST_2 = 1 +PULSE_HALF_2 = 0 +PULSE_CONST_3 = 1 +PULSE_HALF_3 = 0 +PULSE_CONST_4 = 1 +PULSE_HALF_4 = 0 + # SENSOR0 = 0123456789abcdef0123456789abcde0 SENSOR1 = 0123456789abcdef0123456789abcde1 SENSOR2 = 0123456789abcdef0123456789abcde2 SENSOR3 = 0123456789abcdef0123456789abcde3 # -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)"' +CEXTRA = -D DBG=$(DBG) -D PHASE=$(PHASE) -D METERCONST=$(METERCONST) -D PULSE_CONST_2=$(PULSE_CONST_2) -D PULSE_HALF_2=$(PULSE_HALF_2) -D PULSE_CONST_3=$(PULSE_CONST_3) -D PULSE_HALF_3=$(PULSE_HALF_3) -D PULSE_CONST_4=$(PULSE_CONST_4) -D PULSE_HALF_4=$(PULSE_HALF_4) -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 3fad5c1..1ffb5b2 100644 --- a/mote/v1/avr/main.c +++ b/mote/v1/avr/main.c @@ -50,12 +50,12 @@ volatile uint16_t timer = 0; // interrupt service routine for INT0 ISR(INT0_vect) { - pulse_add(&measurements[2], &aux[2]); + pulse_add(&measurements[2], &aux[2], PULSE_CONST_2, PULSE_HALF_2); } // interrupt service routine for INT1 ISR(INT1_vect) { - pulse_add(&measurements[3], &aux[3]); + pulse_add(&measurements[3], &aux[3], PULSE_CONST_3, PULSE_HALF_3); } // interrupt service routine for PCI2 (PCINT20) @@ -65,21 +65,22 @@ ISR(PCINT2_vect) { aux[4].toggle = true; } else { - pulse_add(&measurements[4], &aux[4]); + pulse_add(&measurements[4], &aux[4], PULSE_CONST_4, PULSE_HALF_4); } } **/ -void pulse_add(volatile struct sensor *measurement, volatile struct state *aux) { +void pulse_add(volatile struct sensor *measurement, volatile struct state *aux, uint8_t pulse_const, uint8_t pulse_half) { + measurement->value += pulse_const; + if (aux->half == true) { - measurement->value += PULSE_CONST + 1; + measurement->value += 1; } - else { - measurement->value += PULSE_CONST; + + if (pulse_half) { + aux->half = !aux->half; } -#if PULSE_HALF - aux->half = !aux->half; -#endif + aux->pulse = true; aux->time = time.ms; } diff --git a/mote/v1/avr/main.h b/mote/v1/avr/main.h index ea0a9e1..0444ad2 100644 --- a/mote/v1/avr/main.h +++ b/mote/v1/avr/main.h @@ -50,12 +50,28 @@ #error "METERCONST not defined" #endif -#ifndef PULSE_CONST - #error "PULSE_CONST not defined" +#ifndef PULSE_CONST_2 + #error "PULSE_CONST_2 not defined" #endif -#ifndef PULSE_HALF - #error "PULSE_HALF not defined" +#ifndef PULSE_HALF_2 + #error "PULSE_HALF_2 not defined" +#endif + +#ifndef PULSE_CONST_3 + #error "PULSE_CONST_3 not defined" +#endif + +#ifndef PULSE_HALF_3 + #error "PULSE_HALF_3 not defined" +#endif + +#ifndef PULSE_CONST_4 + #error "PULSE_CONST_4 not defined" +#endif + +#ifndef PULSE_HALF_4 + #error "PULSE_HALF_4 not defined" #endif #define START 0 @@ -125,5 +141,5 @@ struct sensor { // prototypes void WDT_off(void); void WDT_on(void); -void pulse_add(volatile struct sensor *measurement, volatile struct state *aux); +void pulse_add(volatile struct sensor *measurement, volatile struct state *aux, uint8_t pulse_const, uint8_t pulse_half); void send(uint8_t msg_type, const struct sensor *measurement, const struct state *aux);