Skip to main content
AK H
Associate II
May 27, 2023
Question

In STM32F031K6, project file imported has 239.5 cycle set in ADC sampling time. Im getting 200count samples in a sec.(i.e.,each data once in 5ms which is 200Hz). I need to increase the sampling frequency to 200kHz(5uS in time). Pls sugges parameter t

  • May 27, 2023
  • 7 replies
  • 1792 views

..

This topic has been closed for replies.

7 replies

waclawek.jan
Super User
May 27, 2023

System clock frequency, ADC clock source and prescaler, number of channels in a sequence, samping time set for each channel, method how sequences are started and data are read out and - all have impact on the number of conversions of one channel per second.

Read the ADC chapter in RM and proceed accordingly.

JW

AK H
AK HAuthor
Associate II
May 28, 2023

Thanks, for the sampling frequency change does that required to regenerate the code in MX cube or can be edited in main.c file previously generated and used in STM32cubeIDE.

Tesla DeLorean
Guru
May 28, 2023

The compiler builds the code you present it.

You can independently edit the code, rearrange it, change the clock settings and relationships.

You can also use the TIM to trigger the ADC at intervals that differ from the sampling rate, and on some parts you can interleave the ADC to pipeline the sample-hold-conversion.

The STM32F031K6 has one ADC, but can support 1Msps

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AK H
AK HAuthor
Associate II
May 28, 2023

Thanks, for the sampling frequency change does that required to regenerate the code in MX cube or can be edited in main.c file previously generated and used in STM32cubeIDE.

AScha.3
Super User
May 28, 2023

it seems the AI wants to talk us to death...

If you feel a post has answered your question, please click on " Best Answer ".
AK H
AK HAuthor
Associate II
June 1, 2023

If the prescaler is 4, how do I confirm the value of f_adc as 12MHz, sampling cycle set for 239.5 cycle in initialization. If so is it sampling at every 19.95uS. I knew Tconv = (Sampling time + cycles) / (ADC clk). But I am huge difference, getting data every 5ms and sampling time set for 19.95uS. pls correct which part Im missing.

waclawek.jan
Super User
June 1, 2023

> getting data every 5ms

Most likely, the code you are using for "getting data" has an execution time of around 5ms, regardless of how long it takes the ADC to sample and convert one sample.

What we are trying to tell you is, that for anything faster than that, you need to read the manual and write your own code, with understanding of what operation takes how much time to execute. It's not enough to click in CubeMX and call a bunch of Cube functions.

You can start with toggling a pin at various points of your code and observing it using oscilloscope/logic analyser.

JW