diff options
| author | Keith Packard <keithp@keithp.com> | 2013-06-15 01:20:49 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-06-15 01:21:45 -0700 | 
| commit | be9ee9ed2d041c4ab4e77ee2010fe3c7a1ca6597 (patch) | |
| tree | 2ec07a0e0e03157589b51e6d5d67a2e01972af83 /src | |
| parent | 7361371190bf3805b6d0414e61f697aca7c7cff1 (diff) | |
altos/lpc: Filter ADC inputs
They're amazingly noisy on EasyMini, so just filter them as the only
thing we use them for is battery and pyro numbers.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lpc/ao_adc_lpc.c | 39 | ||||
| -rw-r--r-- | src/lpc/ao_arch_funcs.h | 6 | ||||
| -rw-r--r-- | src/lpc/lpc.h | 7 | 
3 files changed, 34 insertions, 18 deletions
| diff --git a/src/lpc/ao_adc_lpc.c b/src/lpc/ao_adc_lpc.c index 25a121b5..40173aa4 100644 --- a/src/lpc/ao_adc_lpc.c +++ b/src/lpc/ao_adc_lpc.c @@ -91,47 +91,58 @@  			 (AO_ADC_6 << 6) |	\  			 (AO_ADC_7 << 7)) -#define AO_ADC_CLKDIV	(AO_LPC_SYSCLK / 4500000 - 1) +#define AO_ADC_CLKDIV	(AO_LPC_SYSCLK / 4500000) -static uint8_t			ao_adc_ready; +static uint8_t		ao_adc_ready; + +static uint16_t		ao_adc_prev[AO_NUM_ADC]; + +#define sample(id)	do {				\ +		uint16_t	p = *prev;		\ +		uint16_t	v = lpc_adc.dr[id];	\ +		p -= p >> 4;				\ +		p += v >> 4;				\ +		*prev++ = p;				\ +		*out++ = p >> 1;			\ +	} while (0)  void  lpc_adc_isr(void)  {  	uint32_t	stat = lpc_adc.stat;  	uint16_t	*out; +	uint16_t	*prev; -	lpc_adc.cr = ((AO_ADC_MASK << LPC_ADC_CR_SEL) | -		      (AO_ADC_CLKDIV << LPC_ADC_CR_CLKDIV) | -		      (0 << LPC_ADC_CR_BURST) | -		      (LPC_ADC_CR_CLKS_11 << LPC_ADC_CR_CLKS)); +	/* Turn off burst mode */ +	lpc_adc.cr = 0;  	lpc_adc.stat = 0;  	/* Store converted values in packet */  	out = (uint16_t *) &ao_data_ring[ao_data_head].adc; +	prev = ao_adc_prev;  #if AO_ADC_0 -	*out++ = lpc_adc.dr[0] >> 1; +	sample(0);  #endif  #if AO_ADC_1 -	*out++ = lpc_adc.dr[1] >> 1; +	sample(1);  #endif  #if AO_ADC_2 -	*out++ = lpc_adc.dr[2] >> 1; +	sample(2);  #endif  #if AO_ADC_3 -	*out++ = lpc_adc.dr[3] >> 1; +	sample(3);  #endif  #if AO_ADC_4 -	*out++ = lpc_adc.dr[4] >> 1; +	sample(4);  #endif  #if AO_ADC_5 -	*out++ = lpc_adc.dr[5] >> 1; +	sample(5);   #endif  #if AO_ADC_6 -	*out++ = lpc_adc.dr[6] >> 1; +	sample(6);  #endif  #if AO_ADC_7 -	*out++ = lpc_adc.dr[7] >> 1; +	sample(7);  #endif  	AO_DATA_PRESENT(AO_DATA_ADC); diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index 179b2f4d..1bbb14f5 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -61,12 +61,10 @@  #define analog_func(id)			lpc_token_evaluator_2(LPC_IOCONF_FUNC_AD,id)  #define ao_enable_analog(port,bit,id) do {				\ -		uint32_t _mode;						\  		ao_enable_port(port);					\  		lpc_gpio.dir[port] &= ~(1 << bit);			\ -		_mode = ((analog_func(id) << LPC_IOCONF_FUNC) |		\ -			 (0 << LPC_IOCONF_ADMODE));			\ -		lpc_ioconf.analog_reg(port,bit) = _mode;		\ +		lpc_ioconf.analog_reg(port,bit) = ((analog_func(id) << LPC_IOCONF_FUNC) | \ +						   (0 << LPC_IOCONF_ADMODE)); \  	} while (0)  #define ARM_PUSH32(stack, val)	(*(--(stack)) = (val)) diff --git a/src/lpc/lpc.h b/src/lpc/lpc.h index 49034c1c..d66f0dd0 100644 --- a/src/lpc/lpc.h +++ b/src/lpc/lpc.h @@ -1169,6 +1169,13 @@ extern struct lpc_adc lpc_adc;  #define  LPC_ADC_CR_CLKS_6		5  #define  LPC_ADC_CR_CLKS_5		6  #define  LPC_ADC_CR_CLKS_4		7 +#define LPC_ADC_CR_START	24 +#define  LPC_ADC_CR_START_NONE		0 +#define  LPC_ADC_CR_START_NOW		1 + +#define LPC_ADC_GDR_CHN			24 +#define LPC_ADC_GDR_OVERRUN		30 +#define LPC_ADC_GDR_DONE		31  #define LPC_ADC_INTEN_ADINTEN	0  #define LPC_ADC_INTEN_ADGINTEN	8 | 
