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 ...
|
# make PHASE=x METERCONST=y SENSOR0=z ...
|
||||||
#
|
#
|
||||||
DBG = 0
|
DBG = 0
|
||||||
#
|
# analog settings
|
||||||
TYPE = 2300501
|
TYPE = 2300501
|
||||||
PHASE = 1
|
PHASE = 1
|
||||||
METERCONST= 5508
|
METERCONST= 5508
|
||||||
|
# pulse settings
|
||||||
|
PULSE_CONST = 1
|
||||||
|
PULSE_HALF = 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 '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>
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
// variable declarations
|
// 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 EEMEM EEPROM_measurements[4] = {{SENSOR0, START}, {SENSOR1, START}, {SENSOR2, START}, {SENSOR3, START}};
|
||||||
volatile struct sensor measurements[4];
|
volatile struct sensor measurements[4];
|
||||||
|
@ -50,16 +50,12 @@ volatile uint16_t timer = 0;
|
||||||
|
|
||||||
// interrupt service routine for INT0
|
// interrupt service routine for INT0
|
||||||
ISR(INT0_vect) {
|
ISR(INT0_vect) {
|
||||||
measurements[2].value++;
|
pulse_add(&measurements[2], &aux[2]);
|
||||||
aux[2].pulse = true;
|
|
||||||
aux[2].time = time.ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// interrupt service routine for INT1
|
// interrupt service routine for INT1
|
||||||
ISR(INT1_vect) {
|
ISR(INT1_vect) {
|
||||||
measurements[3].value++;
|
pulse_add(&measurements[3], &aux[3]);
|
||||||
aux[3].pulse = true;
|
|
||||||
aux[3].time = time.ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// interrupt service routine for PCI2 (PCINT20)
|
// interrupt service routine for PCI2 (PCINT20)
|
||||||
|
@ -69,14 +65,25 @@ ISR(PCINT2_vect) {
|
||||||
aux[4].toggle = true;
|
aux[4].toggle = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
measurements[4].value++;
|
pulse_add(&measurements[4], &aux[4]);
|
||||||
aux[4].pulse = true;
|
|
||||||
aux[4].time = time.ms;
|
|
||||||
aux[4].toggle = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
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
|
// interrupt service routine for ADC
|
||||||
ISR(TIMER2_COMPA_vect) {
|
ISR(TIMER2_COMPA_vect) {
|
||||||
#if DBG > 0
|
#if DBG > 0
|
||||||
|
|
|
@ -50,6 +50,14 @@
|
||||||
#error "METERCONST not defined"
|
#error "METERCONST not defined"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PULSE_CONST
|
||||||
|
#error "PULSE_CONST not defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PULSE_HALF
|
||||||
|
#error "PULSE_HALF not defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define START 0
|
#define START 0
|
||||||
#define END3 0xffffffff
|
#define END3 0xffffffff
|
||||||
#define END2 0xeeeeeeee
|
#define END2 0xeeeeeeee
|
||||||
|
@ -96,6 +104,7 @@ struct time_struct {
|
||||||
struct state {
|
struct state {
|
||||||
boolean pulse;
|
boolean pulse;
|
||||||
boolean toggle;
|
boolean toggle;
|
||||||
|
boolean half;
|
||||||
uint32_t nano;
|
uint32_t nano;
|
||||||
uint16_t adc;
|
uint16_t adc;
|
||||||
|
|
||||||
|
@ -116,4 +125,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 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);
|
||||||
|
|
Loading…
Reference in New Issue