From 8d9da58254aabb37d2c76414ba5a1a6e43518f45 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 12 Mar 2011 01:10:40 +0000 Subject: add ADC prescale flag --- kernel/Makefile | 4 +++- kernel/adc.c | 3 +-- kernel/kernel.h | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'kernel') diff --git a/kernel/Makefile b/kernel/Makefile index 0807a73..810c3d5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -10,6 +10,7 @@ STACK = 64 TASKS = 8 SEMAPHORES = 8 BAUD = 9600 +ADCPRESCALE = 8 # You should not have to change anything below here. @@ -20,7 +21,8 @@ SIZE = avr-size OBJS = ${SRCS:.c=.o} CFLAGS = -Wall -Os -mmcu=${MCU_TARGET} \ -DF_CPU=${F_CPU} -DPRESCALE=${PRESCALE} -DBAUD=${BAUD} \ - -DSTACK=${STACK} -DTASKS=${TASKS} -DSEMAPHORES=${SEMAPHORES} + -DSTACK=${STACK} -DTASKS=${TASKS} -DSEMAPHORES=${SEMAPHORES} \ + -DADCPRESCALE=${ADCPRESCALE} LDFLAGS = -Wl,-Map,${PROG}.map .SUFFIXES: .elf .lst .hex .bin .srec .ehex .ebin .esrec diff --git a/kernel/adc.c b/kernel/adc.c index f48fccd..8f2164d 100644 --- a/kernel/adc.c +++ b/kernel/adc.c @@ -38,8 +38,7 @@ adc(void *arg) a->r = release(); a->d = deadline(); - /* prescale 8 */ - ADCSRA |= (_BV(ADEN) | _BV(ADFR) | _BV(ADPS1) | _BV(ADPS0)); + ADCSRA |= (_BV(ADEN) | _BV(ADFR) | ADC_FLAGS); for (;;) { *a->value = rdadc(a->channel); diff --git a/kernel/kernel.h b/kernel/kernel.h index feab5b0..866ed5c 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -57,6 +57,26 @@ #warning "invalid PRESCALE value" #endif +#if (ADCPRESCALE == 1) +#define ADC_FLAGS 0 +#elif (ADCPRESCALE == 2) +#define ADC_FLAGS _BV(ADPS0) +#elif (ADCPRESCALE == 4) +#define ADC_FLAGS _BV(ADPS1) +#elif (ADCPRESCALE == 8) +#define ADC_FLAGS (_BV(ADPS1) | _BV(ADPS0)) +#elif (ADCPRESCALE == 16) +#define ADC_FLAGS _BV(ADPS2) +#elif (ADCPRESCALE == 32) +#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS0)) +#elif (ADCPRESCALE == 64) +#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS1)) +#elif (ADCPRESCALE == 128) +#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0)) +#else +#warning "invalid ADCPRESCALE value" +#endif + #define SEC(T) ((uint32_t)((T) * (F_CPU / PRESCALE))) #define MSEC(T) ((uint32_t)(T) * ((F_CPU / 1000) / PRESCALE)) #define USEC(T) ((uint32_t)(T) * ((F_CPU / 1000000) / PRESCALE)) -- cgit v1.2.3