ADC sampling time setting.

Post here first, or if you can't find a relevant section!
Post Reply
hermit
Posts: 2
Joined: Fri Jun 03, 2022 4:25 pm

ADC sampling time setting.

Post by hermit »

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?
by ag123 » Fri Jun 03, 2022 6:26 pm
you can use a hardware timer.
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() {	
}
Go to full post
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ADC sampling time setting.

Post by ag123 »

you can use a hardware timer.
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() {	
}
hermit
Posts: 2
Joined: Fri Jun 03, 2022 4:25 pm

Re: ADC sampling time setting.

Post by hermit »

That works. Thank you for your assistance. :D
Post Reply

Return to “General discussion”