aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/adc.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-01-25 10:48:26 -0500
committerKevin O'Connor <kevin@koconnor.net>2020-01-25 10:50:29 -0500
commitbf3fa979f9a75288aaae74214e5e8536a1fa3b6b (patch)
tree336519bc5da42cf0de0606fedb5b552d98e33f1b /src/stm32/adc.c
parent264aac585680b36490ed80625e26efde0482af83 (diff)
downloadkutter-bf3fa979f9a75288aaae74214e5e8536a1fa3b6b.tar.gz
kutter-bf3fa979f9a75288aaae74214e5e8536a1fa3b6b.tar.xz
kutter-bf3fa979f9a75288aaae74214e5e8536a1fa3b6b.zip
stm32: Increase adc sample time
Increase the sample time register from 3 to 4 (which adds about ~1.5us to each adc sample). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32/adc.c')
-rw-r--r--src/stm32/adc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/stm32/adc.c b/src/stm32/adc.c
index ac769c4f..efe71a2f 100644
--- a/src/stm32/adc.c
+++ b/src/stm32/adc.c
@@ -35,9 +35,9 @@ static const uint8_t adc_pins[] = {
#endif
// ADC timing:
-// stm32f103: ADC clock=9Mhz, Tconv=12.5, Tsamp=28.5, total=4.556us
-// stm32f407: ADC clock=21Mhz, Tconv=12, Tsamp=56, total=3.238us
-// stm32f446: ADC clock=22.5Mhz, Tconv=12, Tsamp=56, total=3.022us
+// stm32f103: ADC clock=9Mhz, Tconv=12.5, Tsamp=41.5, total=6.000us
+// stm32f407: ADC clock=21Mhz, Tconv=12, Tsamp=84, total=4.571us
+// stm32f446: ADC clock=22.5Mhz, Tconv=12, Tsamp=84, total=4.267us
struct gpio_adc
gpio_adc_setup(uint32_t pin)
@@ -66,7 +66,7 @@ gpio_adc_setup(uint32_t pin)
// Enable the ADC
if (!is_enabled_pclock(adc_base)) {
enable_pclock(adc_base);
- uint32_t aticks = 3; // 2.5-3.2us (depending on stm32 chip)
+ uint32_t aticks = 4; // 4-6us sample time (depending on stm32 chip)
adc->SMPR1 = (aticks | (aticks << 3) | (aticks << 6) | (aticks << 9)
| (aticks << 12) | (aticks << 15) | (aticks << 18)
| (aticks << 21)