Skip to content

Commit

Permalink
12-bit ADC resolution for STM32 (#20519)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinFor authored and thinkyhead committed Apr 29, 2021
1 parent 231e5a5 commit 076f12e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/thermistor/thermistors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 076f12e

Please sign in to comment.