STM32CubeMX A/D clock setup

Discussions concerning TrueSTUDIO for STM32 9.0.0 and later versions.

Moderators: Markus Girdland, Mattias Norlander

Posts: 18
Joined: Fri Mar 10, 2017 5:32 am

STM32CubeMX A/D clock setup

Postby diamondjimkoehler » Wed Dec 12, 2018 6:49 pm

I have setup a little blue pill STM32F103 as an A/D converter. Using STM32CubeMX, I have set the ADC clock to be 12 MHz. I am sampling with a 7.5 cycle set-up time. The A/D conversion should thus be about 12.5 + 7.5 cycles and should thus take about 1.75 microS. My program uses the software polled, tight loop, A/D conversion as shown in the code here (I'm using TrueSTUDIO 9.1);

Code: Select all

       ptr = 0;
          ADC1->CR2 |= ADC_CR2_ADON;   // turn on the ADC_SR
          while (ptr < total_sample_number)
             ADC1->CR2 |= ADC_CR2_ADON;   // set the ADON bit in the ADC_SR
             while ((ADC1->SR & ADC_SR_JEOC) != 0);  // wait till the EOC bit is set in the ADC_CR2 register
             data[ptr++] = (uint16_t) ADC1->DR;

I have connected a waveform generator producing a 2350 Hz triangular waveform to the channel 0 input. The resulting data, plotted with gnuplot, shows that a 1000 samples of the data corresponds to one cycle of the 2350 Hz waveform. I adjusted the frequency of the waveform generator to get one complete cycle of the waveform in the 1000 samples. That means that a single sample takes about (1 / (1000*2350) ) of a second; about 0.425 microS. This is about 4 times faster than I would expect.
I conclude from this that STM32CubeMX is not really setting the ADC clock properly ... is there a better explanation? I've looked at the waveform with an oscilloscope and it is, indeed, 2350 Hz as close as one can tell looking at it.

Posts: 18
Joined: Fri Mar 10, 2017 5:32 am

Re: STM32CubeMX A/D clock setup

Postby diamondjimkoehler » Thu Dec 13, 2018 7:11 pm

Oops ... please disregard this previous post of mine. I have some other problems and STM32CubeMX does not seem to be one of them. When I looked at the code written by STM32CubeMX, I see that it did correctly configure the clock. Why the compiled program executed the A/D conversion so fast is some other problem and I am having trouble with the STLINK I am using sO I have not been able to resolve it.

Return to “TrueSTUDIO for STM32 discussions”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests