avr: make pulse constant and half parameters configurable per input

This commit is contained in:
Bart Van Der Meerssche 2010-10-10 20:06:11 +02:00
parent 8f1836e8b8
commit e5e352d5ca
3 changed files with 40 additions and 18 deletions

View File

@ -52,15 +52,20 @@ TYPE = 2300501
PHASE = 1 PHASE = 1
METERCONST= 5508 METERCONST= 5508
# pulse settings # pulse settings
PULSE_CONST = 1 PULSE_CONST_2 = 1
PULSE_HALF = 0 PULSE_HALF_2 = 0
PULSE_CONST_3 = 1
PULSE_HALF_3 = 0
PULSE_CONST_4 = 1
PULSE_HALF_4 = 0
# #
SENSOR0 = 0123456789abcdef0123456789abcde0 SENSOR0 = 0123456789abcdef0123456789abcde0
SENSOR1 = 0123456789abcdef0123456789abcde1 SENSOR1 = 0123456789abcdef0123456789abcde1
SENSOR2 = 0123456789abcdef0123456789abcde2 SENSOR2 = 0123456789abcdef0123456789abcde2
SENSOR3 = 0123456789abcdef0123456789abcde3 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)"'
############################################################################### ###############################################################################

View File

@ -50,12 +50,12 @@ volatile uint16_t timer = 0;
// interrupt service routine for INT0 // interrupt service routine for INT0
ISR(INT0_vect) { 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 // interrupt service routine for INT1
ISR(INT1_vect) { 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) // interrupt service routine for PCI2 (PCINT20)
@ -65,21 +65,22 @@ ISR(PCINT2_vect) {
aux[4].toggle = true; aux[4].toggle = true;
} }
else { 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) { 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->pulse = true;
aux->time = time.ms; aux->time = time.ms;
} }

View File

@ -50,12 +50,28 @@
#error "METERCONST not defined" #error "METERCONST not defined"
#endif #endif
#ifndef PULSE_CONST #ifndef PULSE_CONST_2
#error "PULSE_CONST not defined" #error "PULSE_CONST_2 not defined"
#endif #endif
#ifndef PULSE_HALF #ifndef PULSE_HALF_2
#error "PULSE_HALF not defined" #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 #endif
#define START 0 #define START 0
@ -125,5 +141,5 @@ struct sensor {
// prototypes // prototypes
void WDT_off(void); void WDT_off(void);
void WDT_on(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); void send(uint8_t msg_type, const struct sensor *measurement, const struct state *aux);