stm32: Increase sample time in stm32h7_adc.c

The existing sample times are not long enough to reliably sample the
internal temperature sensor.  Longer sample times should also improve
results with temperature sensors that have a higher inductance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-01-11 22:14:53 -05:00
parent 33f973e452
commit 80943d3846
1 changed files with 10 additions and 7 deletions

View File

@ -156,11 +156,12 @@ static const uint8_t adc_pins[] = {
// ADC timing // ADC timing
#define ADC_CKMODE 0b11 #define ADC_CKMODE 0b11
#define ADC_ATICKS (CONFIG_MACH_STM32H7 ? 0b101 : 0b100) #define ADC_ATICKS 0b110
// stm32h7: clock=25Mhz, Tsamp=64.5, Tconv=71, total=2.84us #define ADC_ATICKS_H723_ADC3 0b111
// stm32h723 adc3: clock=50Mhz, Tsamp=92.5, Tconv=105, total=2.1us // stm32h7: clock=25Mhz, Tsamp=387.5, Tconv=394, total=15.76us
// stm32l4: clock=20Mhz, Tsamp=47.5, Tconv=60, total=3.0us // stm32h723 adc3: clock=50Mhz, Tsamp=640.5, Tconv=653, total=13.06us
// stm32g4: clock=37.5Mhz, Tsamp=47.5, Tconv=60, total=1.6us // stm32l4: clock=20Mhz, Tsamp=247.5, Tconv=260, total=13.0us
// stm32g4: clock=37.5Mhz, Tsamp=247.5, Tconv=260, total=6.933us
// Handle register name differences between chips // Handle register name differences between chips
#if CONFIG_MACH_STM32H723 #if CONFIG_MACH_STM32H723
@ -217,8 +218,11 @@ gpio_adc_setup(uint32_t pin)
; ;
// Setup chip specific flags // Setup chip specific flags
uint32_t aticks = ADC_ATICKS;
#if CONFIG_MACH_STM32H7 #if CONFIG_MACH_STM32H7
if (!(CONFIG_MACH_STM32H723 && adc == ADC3)) { if (CONFIG_MACH_STM32H723 && adc == ADC3) {
aticks = ADC_ATICKS_H723_ADC3;
} else {
// Use linear calibration on stm32h7 // Use linear calibration on stm32h7
cr |= ADC_CR_ADCALLIN; cr |= ADC_CR_ADCALLIN;
// Set boost mode on stm32h7 (adc clock is at 25Mhz) // Set boost mode on stm32h7 (adc clock is at 25Mhz)
@ -241,7 +245,6 @@ gpio_adc_setup(uint32_t pin)
; ;
// Set ADC clock cycles sample time for every channel // Set ADC clock cycles sample time for every channel
uint32_t aticks = ADC_ATICKS;
uint32_t av = (aticks | (aticks << 3) | (aticks << 6) uint32_t av = (aticks | (aticks << 3) | (aticks << 6)
| (aticks << 9) | (aticks << 12) | (aticks << 15) | (aticks << 9) | (aticks << 12) | (aticks << 15)
| (aticks << 18) | (aticks << 21) | (aticks << 24) | (aticks << 18) | (aticks << 21) | (aticks << 24)