diff --git a/uc/Makefile b/uc/Makefile index fb2d8ae..d6f2d35 100755 --- a/uc/Makefile +++ b/uc/Makefile @@ -81,19 +81,20 @@ AVRDUDE_PROGRAMMER = usbtiny MCU = atmega48 F_CPU = 1000000 # -# Predefine the TYPE and SENSORx C macros in main.h via this Makefile. Override the -# defaults on the command line by typing: +# Predefine the TYPE and SENSORx C macros in main.h via this Makefile. +# Override the defaults on the command line by typing: # make TYPE=xxxx SENSOR0=yyyy ... # -TYPE = 2301 -METERCONST = 7091 +DBG = 0 +# +TYPE = 2300501 # SENSOR0 = 0123456789abcdef0123456789abcde0 SENSOR1 = 0123456789abcdef0123456789abcde1 SENSOR2 = 0123456789abcdef0123456789abcde2 SENSOR3 = 0123456789abcdef0123456789abcde3 # -CEXTRA = -D TYPE=$(TYPE) -D METERCONST=$(METERCONST) -D POWERCONST=$(POWERCONST) -D 'SENSOR0="$(SENSOR0)"' -D 'SENSOR1="$(SENSOR1)"' -D 'SENSOR2="$(SENSOR2)"' -D 'SENSOR3="$(SENSOR3)"' +CEXTRA = -D DBG=$(DBG) -D TYPE=$(TYPE) -D 'SENSOR0="$(SENSOR0)"' -D 'SENSOR1="$(SENSOR1)"' -D 'SENSOR2="$(SENSOR2)"' -D 'SENSOR3="$(SENSOR3)"' ##################################################################################### ##################################################################################### diff --git a/uc/main.c b/uc/main.c index 6d28722..a7d6019 100644 --- a/uc/main.c +++ b/uc/main.c @@ -73,43 +73,49 @@ ISR(PCINT2_vect) { **/ // interrupt service routine for ADC -ISR(TIMER2_OVF_vect) { +ISR(TIMER2_COMPA_vect) { +#if DBG > 0 + PORTD |= (1< WATT) { - measurements[muxn].value++; - aux[muxn].pulse = true; - aux[muxn].nano -= WATT; - aux[muxn].pulse_count++; - } - - if (timer == SECOND) { - aux[muxn].nano_start = aux[muxn].nano_end; - aux[muxn].nano_end = aux[muxn].nano; - aux[muxn].pulse_count_final = aux[muxn].pulse_count; - aux[muxn].pulse_count = 0; - aux[muxn].power = true; - } + if (aux[muxn].nano > WATT) { + measurements[muxn].value++; + aux[muxn].pulse = true; + aux[muxn].nano -= WATT; + aux[muxn].pulse_count++; } - // rotate the available ADC input channels (0 to 7) + if (timer == SECOND) { + aux[muxn].nano_start = aux[muxn].nano_end; + aux[muxn].nano_end = aux[muxn].nano; + aux[muxn].pulse_count_final = aux[muxn].pulse_count; + aux[muxn].pulse_count = 0; + aux[muxn].power = true; + } + + // cycle through the available ADC input channels (0 and 1) muxn++; - if (!(muxn &= 0x7)) timer++; + if (!(muxn &= 0x1)) timer++; if (timer > SECOND) timer = 0; - // but only use ADC0 and 1 - if (muxn < 2) { - ADMUX &= 0xF8; - ADMUX |= muxn; - - // start a new ADC conversion - ADCSRA |= (1< 0 + PORTD &= ~(1< 1 + aux[muxn].nano = WATT+1; + timer = SECOND; +#endif +} + // interrupt service routine for analog comparator ISR(ANALOG_COMP_vect) { uint8_t i; @@ -197,7 +203,10 @@ void setup() // enable INT0 and INT1 interrupts EIMSK = (1< 0 + // re-use PD4 pin for tracing interrupt times + DDRD |= (1< fTOV2 = 1000kHz / 256 / 1 = 3906.24Hz (DS p.158) - TCCR2B |= (1< 0 + // Toogle pin OC2A=PB3 on compare match + TCCR2A |= 1< fTOV2 = 1000kHz / 256 / 8 = 488.28Hz (DS p.158) + TCCR2B |= (1<