ADC sampling time setting.
ADC sampling time setting.
Hi, I'm using an ADC1 IN0 on an STM32F103C8xx to measure temperature with an NTC100K thermistor. My code works fine but I have a question about the sample rate. So according to the STM32 reference manual I've calculated that when I set the Sampling Time in CubeIDE to 239,5 (maximum) the ADC will return a measurement every 21us - (239,5 + 12,5)/12. Is there a way to configure the ADC to get a measurement every cca 15ms?
you can use a hardware timer.
https://github.com/stm32duino/wiki/wiki ... er-library
Go to full posthttps://github.com/stm32duino/wiki/wiki ... er-library
Code: Select all
HardwareTimer timer(TIM1);
void readAdc() {
uint16_t value = analogRead(pin);
...
}
void setup() {
timer.pause();
timer.setoverflow(15000,, MICROSEC_FORMAT);
timer.refresh();
timer.attachInterrupt(readAdc);
timer.resume();
}
void loop() {
}
Re: ADC sampling time setting.
you can use a hardware timer.
https://github.com/stm32duino/wiki/wiki ... er-library
https://github.com/stm32duino/wiki/wiki ... er-library
Code: Select all
HardwareTimer timer(TIM1);
void readAdc() {
uint16_t value = analogRead(pin);
...
}
void setup() {
timer.pause();
timer.setoverflow(15000,, MICROSEC_FORMAT);
timer.refresh();
timer.attachInterrupt(readAdc);
timer.resume();
}
void loop() {
}
Re: ADC sampling time setting.
That works. Thank you for your assistance.