From 36aff1e4646ada018512ff0ee0c8a27205d8c260 Mon Sep 17 00:00:00 2001 From: LinFor Date: Tue, 22 Dec 2020 03:30:03 +0300 Subject: [PATCH] 12-bit ADC resolution for STM32 (#20519) --- Marlin/src/HAL/STM32/HAL.h | 6 +++--- Marlin/src/module/thermistor/thermistors.h | 2 ++ .../share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index f2fb5ddb6a..b1c27e4ec5 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -159,14 +159,14 @@ static inline int freeMemory() { #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT) -inline void HAL_adc_init() {} - #define HAL_ADC_VREF 3.3 -#define HAL_ADC_RESOLUTION 10 +#define HAL_ADC_RESOLUTION ADC_RESOLUTION // 12 #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin) #define HAL_READ_ADC() HAL_adc_result #define HAL_ADC_READY() true +inline void HAL_adc_init() { analogReadResolution(HAL_ADC_RESOLUTION); } + void HAL_adc_start_conversion(const uint8_t adc_pin); uint16_t HAL_adc_get_result(); diff --git a/Marlin/src/module/thermistor/thermistors.h b/Marlin/src/module/thermistor/thermistors.h index 340712e22d..03ed5c2a57 100644 --- a/Marlin/src/module/thermistor/thermistors.h +++ b/Marlin/src/module/thermistor/thermistors.h @@ -27,6 +27,8 @@ #define THERMISTOR_TABLE_SCALE (HAL_ADC_RANGE / _BV(THERMISTOR_TABLE_ADC_RESOLUTION)) #if ENABLED(HAL_ADC_FILTERED) #define OVERSAMPLENR 1 +#elif HAL_ADC_RESOLUTION > 10 + #define OVERSAMPLENR (20 - HAL_ADC_RESOLUTION) #else #define OVERSAMPLENR 16 #endif diff --git a/buildroot/share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h b/buildroot/share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h index ee4b1ef296..07e2cad3f9 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h +++ b/buildroot/share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h @@ -114,6 +114,8 @@ extern "C" { #define NUM_ANALOG_INPUTS 7 #define NUM_ANALOG_FIRST 80 +#define ADC_RESOLUTION 12 + // PWM resolution // #define PWM_RESOLUTION 12 #define PWM_FREQUENCY 20000 // >= 20 Khz => inaudible noise for fans