From 7f4aaf97c3ab5970324c146faccad53e7b081677 Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Tue, 31 Dec 2019 13:16:14 +0100 Subject: [PATCH] Moved cal register definitions to mcu.h --- src/adc_dma.cpp | 28 ---------------------------- src/mcu.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/adc_dma.cpp b/src/adc_dma.cpp index 70a1daa..fd785e2 100644 --- a/src/adc_dma.cpp +++ b/src/adc_dma.cpp @@ -18,36 +18,10 @@ #include "debug.h" #include "pcb.h" // contains defines for pins -// factory calibration values for internal voltage reference and temperature sensor -// (see MCU datasheet, not RM) -#if defined(STM32F0) - const uint16_t VREFINT_CAL = *((uint16_t *)0x1FFFF7BA); // VREFINT @3.3V/30°C - #define VREFINT_VALUE 3300 // mV - const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FFFF7B8); - const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FFFF7C2); - #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point - #define TSENSE_CAL2_VALUE 110.0 // temperature of second calibration point -#elif defined(STM32L0) - const uint16_t VREFINT_CAL = *((uint16_t *)0x1FF80078); // VREFINT @3.0V/25°C - #define VREFINT_VALUE 3000 // mV - const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FF8007A); - const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FF8007E); - #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point - #define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point -#elif defined(UNIT_TEST) - #define VREFINT_CAL (4096 * 1.224 / 3.0) // VREFINT @3.0V/25°C - #define VREFINT_VALUE 3000 // mV - #define TSENSE_CAL1 (4096.0 * (670 - 161) / 3300) // datasheet: slope 1.61 mV/°C - #define TSENSE_CAL2 (4096.0 * 670 / 3300) // datasheet: 670 mV - #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point - #define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point -#endif - #if defined(__MBED__) && defined(PIN_REF_I_DCDC) AnalogOut ref_i_dcdc(PIN_REF_I_DCDC); #endif - static float solar_current_offset; static float load_current_offset; @@ -102,10 +76,8 @@ static inline float ntc_temp(uint32_t channel, int32_t vcc) float rts = NTC_SERIES_RESISTOR * v_temp / (vcc - v_temp); // resistance of NTC (Ohm) return 1.0/(1.0/(273.15+25) + 1.0/NTC_BETA_VALUE*log(rts/10000.0)) - 273.15; // °C - } - void calibrate_current_sensors() { int vcc = VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU); diff --git a/src/mcu.h b/src/mcu.h index 509f04e..7f67eb4 100644 --- a/src/mcu.h +++ b/src/mcu.h @@ -27,4 +27,29 @@ #include "stm32f072xx.h" #endif +// factory calibration values for internal voltage reference and temperature sensor +// (see MCU datasheet, not Reference Manual) +#if defined(STM32F0) + const uint16_t VREFINT_CAL = *((uint16_t *)0x1FFFF7BA); // VREFINT @3.3V/30°C + #define VREFINT_VALUE 3300 // mV + const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FFFF7B8); + const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FFFF7C2); + #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point + #define TSENSE_CAL2_VALUE 110.0 // temperature of second calibration point +#elif defined(STM32L0) + const uint16_t VREFINT_CAL = *((uint16_t *)0x1FF80078); // VREFINT @3.0V/25°C + #define VREFINT_VALUE 3000 // mV + const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FF8007A); + const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FF8007E); + #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point + #define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point +#elif defined(UNIT_TEST) + #define VREFINT_CAL (4096 * 1.224 / 3.0) // VREFINT @3.0V/25°C + #define VREFINT_VALUE 3000 // mV + #define TSENSE_CAL1 (4096.0 * (670 - 161) / 3300) // datasheet: slope 1.61 mV/°C + #define TSENSE_CAL2 (4096.0 * 670 / 3300) // datasheet: 670 mV + #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point + #define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point +#endif + #endif // MCU_H_