From c4ffe80e8035fae56bae0fb7f4adc8260c21153c Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Tue, 1 Sep 2020 02:30:45 +0200 Subject: [PATCH] move calibration values to defines --- newcode/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/newcode/main.c b/newcode/main.c index 3ed9da1..ba9c0bd 100644 --- a/newcode/main.c +++ b/newcode/main.c @@ -8,10 +8,15 @@ #define AVRG 512 +#define SUPPLY_VOLTS 3.3 +#define REF_OHMS 993.5 + +#define ADC_0V_COUNT 170 +#define ADC_MAX_VOLT 1.95 + volatile uint16_t adc_buffer[AVRG]; volatile float ch_values[9]; - void init_clk(void) { // ========= System Clock configuration ========= @@ -160,10 +165,10 @@ ISR(DMA_CH0_vect){ ADCA.CH0.MUXCTRL = pin << ADC_CH_MUXPOS_gp; // give MUX time to switch during averaging float temp = avrg(adc_buffer, AVRG); - temp = temp - 170; - temp = (temp)/ 3926 * 1.95; - temp = (temp*993.5)/(3.3-temp); - temp = (temp-100)/0.3927; + temp = temp - ADC_0V_COUNT; + temp = (temp)/ (4096-ADC_0V_COUNT) * ADC_MAX_VOLT; + temp = (temp * REF_OHMS)/(SUPPLY_VOLTS - temp); + temp = (temp-100)/0.3927; //pt100 formula ch_values[old_pin] = temp; DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_ADCA_CH0_gc;