diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ao_adc.c | 12 | ||||
| -rw-r--r-- | src/ao_convert.c | 10 | 
2 files changed, 16 insertions, 6 deletions
diff --git a/src/ao_adc.c b/src/ao_adc.c index b0bfceb1..2b972e6c 100644 --- a/src/ao_adc.c +++ b/src/ao_adc.c @@ -46,16 +46,18 @@ ao_adc_isr(void) interrupt 1  	uint8_t	__xdata *a;  	sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT; +	if (sequence == ADCCON3_ECH_TEMP) +		sequence = 2;  	a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence);  	a[0] = ADCL;  	a[1] = ADCH;  	if (sequence < 5) {  		/* start next channel conversion */ -		sequence++; -		/* skip channel 2, we don't have a temp sensor on v0.2 */ -		if (sequence == 2) -			sequence++; -		ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | sequence; +		/* v0.2 replaces external temp sensor with internal one */ +		if (sequence == 1) +			ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP; +		else +			ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1);  	} else {  		/* record this conversion series */  		ao_adc_ring[ao_adc_head].tick = ao_time(); diff --git a/src/ao_convert.c b/src/ao_convert.c index 57ed7370..f29ce9e9 100644 --- a/src/ao_convert.c +++ b/src/ao_convert.c @@ -49,7 +49,15 @@ ao_temp_to_dC(int16_t temp) __reentrant  	int16_t	ret;  	ao_mutex_get(&ao_temp_mutex); -	ret = (int16_t) ((temp >> 4) * 3300L / 2047L) - 500; +	/* Output voltage at 0°C = 0.755V +	 * Coefficient = 0.00247V/°C +	 * Reference voltage = 1.25V +	 * +	 * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 +	 *      = (value - 19791.268) / 32768 * 1.25 / 0.00247 +	 *	≃ (value - 19791) * 1012 / 65536 +	 */ +	ret = ((temp - 19791) * 1012L) >> 16;  	ao_mutex_put(&ao_temp_mutex);  	return ret;  }  | 
