Browse Source

12-bit ADC resolution for STM32 (#20519)

LinFor 4 years ago
parent
commit
36aff1e464
No account linked to committer's email address

+ 3
- 3
Marlin/src/HAL/STM32/HAL.h View File

159
 
159
 
160
 #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
160
 #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
161
 
161
 
162
-inline void HAL_adc_init() {}
163
-
164
 #define HAL_ADC_VREF         3.3
162
 #define HAL_ADC_VREF         3.3
165
-#define HAL_ADC_RESOLUTION  10
163
+#define HAL_ADC_RESOLUTION  ADC_RESOLUTION // 12
166
 #define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
164
 #define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
167
 #define HAL_READ_ADC()      HAL_adc_result
165
 #define HAL_READ_ADC()      HAL_adc_result
168
 #define HAL_ADC_READY()     true
166
 #define HAL_ADC_READY()     true
169
 
167
 
168
+inline void HAL_adc_init() { analogReadResolution(HAL_ADC_RESOLUTION); }
169
+
170
 void HAL_adc_start_conversion(const uint8_t adc_pin);
170
 void HAL_adc_start_conversion(const uint8_t adc_pin);
171
 
171
 
172
 uint16_t HAL_adc_get_result();
172
 uint16_t HAL_adc_get_result();

+ 2
- 0
Marlin/src/module/thermistor/thermistors.h View File

27
 #define THERMISTOR_TABLE_SCALE (HAL_ADC_RANGE / _BV(THERMISTOR_TABLE_ADC_RESOLUTION))
27
 #define THERMISTOR_TABLE_SCALE (HAL_ADC_RANGE / _BV(THERMISTOR_TABLE_ADC_RESOLUTION))
28
 #if ENABLED(HAL_ADC_FILTERED)
28
 #if ENABLED(HAL_ADC_FILTERED)
29
   #define OVERSAMPLENR 1
29
   #define OVERSAMPLENR 1
30
+#elif HAL_ADC_RESOLUTION > 10
31
+  #define OVERSAMPLENR (20 - HAL_ADC_RESOLUTION)
30
 #else
32
 #else
31
   #define OVERSAMPLENR 16
33
   #define OVERSAMPLENR 16
32
 #endif
34
 #endif

+ 2
- 0
buildroot/share/PlatformIO/variants/MARLIN_FYSETC_S6/variant.h View File

114
 #define NUM_ANALOG_INPUTS       7
114
 #define NUM_ANALOG_INPUTS       7
115
 #define NUM_ANALOG_FIRST        80
115
 #define NUM_ANALOG_FIRST        80
116
 
116
 
117
+#define ADC_RESOLUTION          12
118
+
117
 // PWM resolution
119
 // PWM resolution
118
 // #define PWM_RESOLUTION          12
120
 // #define PWM_RESOLUTION          12
119
 #define PWM_FREQUENCY           20000 // >= 20 Khz => inaudible noise for fans
121
 #define PWM_FREQUENCY           20000 // >= 20 Khz => inaudible noise for fans

Loading…
Cancel
Save