ADC sample rate of 5 Ms/s on bluepill STM32F103

Post here first, or if you can't find a relevant section!
bit_factory
Posts: 7
Joined: Sun Jan 26, 2020 11:23 pm

ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by bit_factory »

Helo everybody,
I'm just a little bit confused about the maximum sample speed in dual interleaved mode for the STM32F103 chip.
I start to play using pig-o-scope code. My goal was to develope this simply but good project, adding some new features. One of them the ability of setting different sample rate. At the first I played with adc_set_sample_rate function. At beginning seems to work well but analizyng the sample I discovered that settings different from ADC_SMPR_1_5 corrupts the sample stepping it. So I went for ADC prescaler settings. I discovered that the default adc prescaler value is ADC_PRE_PCLK2_DIV_6 that @72MHz and ADC_SMPR_1_5 gives about 0.58 us per sample with a sample rate of 1724 Ks/s. I was very astonished when I play with different value of prescaler, infact using a prescaler divider of 2 (ADC_PRE_PCLK2_DIV_2) i could fill the sample buffer of size 6144 of uint16_t in about 1196 us with a time per sample of about 0.19 us and so a sample rate of 5137 ks/s (about 5 Ms/s).
Doing some calculation the time for sample and the sample rate seems to be correct infact at ADC_PRE_PCLK2_DIV_2 the ADC clock should be 72 MHz / 2 = 36 MHz and with ADC_SMPR_1_5 a sample is taken every 12.5 + 1.5 = 14 cycles. 36MHz / 14 about 2,571 that (in dual interleaved) x 2 does 5.142.
Reading the device datasheet the absolute maximum rating of ADC clock is 14 Mhz (that in dual interleaved make 2 Ms/s) but my bluepill is well working with a clock of 36 MHz.
My question is anyone has ever played with this settings with such results.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by ag123 »

nice finding, i think one of the factors is at the higher mhz sampling rates, the sampling capacitors would take a longer time to fill
hence one of the concern would be that for high impedance/resistance loads (i.e. small currents) it would possibly be less than those mhz rates
that can be adequately sampled.
but nevertheless, this isn't limited to the mhz sampling rates, even with normal rates, with high impedance sources
i've had to use large sampling times which significantly limits sample rates sometimes well below 1msps
User avatar
Pito
Posts: 94
Joined: Tue Dec 24, 2019 1:53 pm

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by Pito »

Even with 0ohm source the is an internal Radc and sampling capacitor Cadc.
Radc is usualy 1k-10k and Cadc 5-15pF (doublecheck the DS).
That limits the sampling rate, as you have to fully charge the Cadc via Rsource+Radc between the samples within the ADC input voltage limits.
Pukao Hats Cleaning Services Ltd.
bit_factory
Posts: 7
Joined: Sun Jan 26, 2020 11:23 pm

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by bit_factory »

The fact is that I'm really sampling very well a pwm out pin at 5 Ms/s. It is working opposite it should not.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by stevestrong »

The fact that the sampling is working at such high speed does not tell much about the correctness of the sampled value.
You may have a full buffer of values which do not reflect the reality. It may seem ok for digital signals, but I have doubts about analog signals with high impedance.
bit_factory
Posts: 7
Joined: Sun Jan 26, 2020 11:23 pm

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by bit_factory »

@stevestrong you are really right. But at the moment sampling Pwm pin with a 4.7uf cap between output and GND (just to have a waveform slighty different from a square one) the trace @5Ms/s it is really similar if not equal to the one @1.7 Ms/s. Visually I can compare the trace cause my routine can vary runtime the prescaler value (keeping the DSO Hdiv virtually constant). Switching prescaler the trace seems to be really stable. Reading DSs I'm pretty sure this result should not be possible or strongly erratic but is not.
My next step is to export the data set @5Ms/s and the 1.7 Ms/s one and deep compare the two.
Visually I can only assert that at highs sample rates, very very often the trace shows down spikes in the high ADC values and I think this is explained according the @Pito statement "That limits the sampling rate, as you have to fully charge the Cadc via Rsource+Radc between the samples within the ADC input voltage limits".
Just a question to everybody: does someone knows if the calibrate adc function is affected by present adc configuration, i.e. if it takes in account the setting of prescaler dividing, resolution, etc at the moment of execution or is a fixed routine not affected by all.
I ask this because accordind DSs, is higly suggested to perform adc calibration at startup, and so I do in the sketch, but adc settings are changed during runtime by user request and if the calibration is affected by adc config I should run it at every setting change.
Thank in advance
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by ag123 »

i think given the benefit of doubt bit_factory is likely correct, this is a little like attempts to overclock the mcu.
for the stm32f401, spec rates is 84mhz
i tried 96mhz and found it works just ok
viewtopic.php?p=539#p539
the highest i go is 144mhz barely working
i'd guess between the devices, the 'good' stm32f1 devices possibly can do the high mhz sampling speeds
if you can feed a low impedence source e.g. a good voltage follower stage or an emitter follower bjt, before the adc
chances are that it may reach those higher than specs sample speeds
as it won't be possible for st to test every device, the provided values are sometimes statistically tested values that is proven to work
unlike the more expensive processors e.g. from intel / amd etc. they do binning and sell those that can run at higher clock rates expensively
e.g. for intel often named the K series and for amd the X series
for stm32, you are given the (whole) bin and you select the good apples yourself
and for all we know, if they run out of capacity say to do 180 nm node for stm32f103, they may use 90nm node that is designated for f4 if there are spare capacity, so you get a f4 quality stm32f103 e.g. 2.5mhz adc speeds for the price of stm32f103
(if dennard scaling still works at 90nm, the transistor and probably sampling capacitor is 1/4 the area for every 1/2 reduction in nm node sizes)
:lol:
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by ag123 »

i tried things like making pencil resistors on paper, for the same 2B pencil, color that thin i get 1-5M ohm, color that thick i sometimes get 100k ohms if i'm lucky
:lol:
bit_factory
Posts: 7
Joined: Sun Jan 26, 2020 11:23 pm

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by bit_factory »

ag123 thank you for the answer. :D
I'm looking for a good input stage with single supply op-amp schematic now that can shift AC source to adc levels, decopuling it, etc.
I'm not so experienced in analog circuitry so I will be grateful if you can suggest me a simple circuit with a decent and "cheap" IC that cold do the work.
Thank in advance
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ADC sample rate of 5 Ms/s on bluepill STM32F103

Post by ag123 »

well, i mess with all these pretty much as a hobby, hence i'd not be able to really advise on the electronics :P

if i read the tutorials correctly, voltage followers are classically done with op amps
https://www.electronics-tutorials.ws/opamp/opamp_3.html
my guess is things like lmv358 dual op amp, lmv324 quad op amp could help there
https://www.ti.com/product/LMV324
http://www.ti.com/product/LMV358
but for these low cost op amps, they may not be able to handle those sharp edge mhz digital signals (slew rates etc)
i'm not sure if funky digitals ics like 74hc244,245
https://assets.nexperia.com/documents/d ... HCT244.pdf
https://assets.nexperia.com/documents/d ... HCT245.pdf
may be able to 'fake' those high speeds op amps, however, as this is a digital ic only digital signal levels are given.
i'm not sure how effective can they be used in analog context
if it is possible to use them that way, it is a very cheap way to do all that buffering

emitter follower is that common collector circuit
https://en.wikipedia.org/wiki/Common_collector
the voltage at the emitter resistor is nearly always Vbe ~ 0.7v, i.e. if input Vb is 3v, 3 - 0.7 ~ 2.3v appears at the emitter pin
it seem Re (emitter resistor) can be quite low like 10 ohms, but of course it would drain quite a bit of current that way especially when Vb is on
emitter follower has the downside that your input voltage needs to be > 0.7v for the transistor to conduct.
voltage followers (op amps) do away with that with the elaborate op amp internal circuits

it seemed more appropriate to use specific ic for those buffers, and not all of them looks expensive
https://www.ti.com/amplifier-circuit/op ... rview.html
it seemed that rather cheap buffers (i.e. unity gain op amps) are after all rather common
https://www.maximintegrated.com/en/prod ... X4012.html
https://www.aliexpress.com/wholesale?ca ... xt=MAX4016
https://docs.rs-online.com/386e/0900766b804feb67.pdf
https://www.aliexpress.com/wholesale?ca ... ext=ad8091
Post Reply

Return to “General discussion”