From 985484179bf8a520dc934d47154df00df1f34663 Mon Sep 17 00:00:00 2001 From: David Lenfesty <6893214+davidlenfesty@users.noreply.github.com> Date: Fri, 25 Oct 2019 13:26:23 -0600 Subject: [PATCH] Added diode calibration --- lab_3/main.c | 10 +++++----- lab_3/main.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lab_3/main.c b/lab_3/main.c index e1cbb56..4ca0c2d 100755 --- a/lab_3/main.c +++ b/lab_3/main.c @@ -66,16 +66,16 @@ uint16_t adc_run_conversion(uint8_t adc_selection) { /** @brief Converts an ADC value from a measurement on an LM35 into a temperature. */ int8_t lm35_convert(uint16_t adc_reading) { - return (float) (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY; + return (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY; } /** @brief Converts and ADC value from a measurement on a diode into a temperature. - * TODO */ int8_t diode_convert(uint16_t adc_reading) { - // Do some funky math here - - return 0; + // This could be collapsed but it doesn't really matter + int16_t value_diff = adc_reading - DIODE_VALUE_25C; + int16_t temp_diff = value_diff / DIODE_SENSITIVITY; + return temp_diff + 25; } int main() { diff --git a/lab_3/main.h b/lab_3/main.h index d7a5c87..a1e001a 100644 --- a/lab_3/main.h +++ b/lab_3/main.h @@ -13,8 +13,8 @@ #define ADC_VREF 1.1 #define ADC_RESOLUTION 1023 // (2^ 10 - 1, 10 bits resolution) -#define DIODE_VALUE_0C // ADC value for diode at 0C -#define DIODE_SENSITIVITY 0.0025 // V / degree C, tuneable +#define DIODE_VALUE_25C 436 // ADC value for diode at 0C +#define DIODE_SENSITIVITY -1.85 // ADC value / degree C, tuneable #define LM35_SENSITIVITY 0.01 // V / degree C, see LM35 datasheet