avr: add support for a configurable PULSE_CONST and PULSE_HALF
This commit is contained in:
parent
09fd007bb2
commit
8032327cc2
|
@ -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)"'
|
||||
###############################################################################
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <avr/wdt.h>
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue