Skip to main content
Visitor II
September 18, 2024
Solved

How to test real ADC frequency and its accuracy?

  • September 18, 2024
  • 3 replies
  • 1680 views

Hi guys,

 

I'd like to test if the true ADC frequency is the same as what I've set. The ADC setting is HSI14 (14 MHz) as clock source, 12 bits resolution (corresponds to 12.5 ADC clock cycles), sampling time is 1.5 clock cycles. Therefore, one conversion time should be, according to user manual, (1.5+12.5) / (14 MHz) = 1 microseconds. What can I do to test if each conversion is really that fast and how to export each ADC data to a spreadsheet (csv or xslx files) for further analysis under such high speed? I suppose using Tera Term to log data doesn't work since the maximum baud rate is 921600 and what I'm using is 115200, both of which are less than 1 million, does it make sense?

I'm using STM32F0308 board and CooCox CoIDE.

I'm new to STM32 and this community, if there's anything I can do next time to propose a better question, please let me know, thank you for reading.

 

 

    This topic has been closed for replies.
    Best answer by TDK

    > What can I do to test if each conversion is really that fast

    Set up circular conversions to a large internal buffer, say 1000 samples. When the conversion complete callback is called, read the time. Do this for 101 consecutive times and take the difference in time (or system ticks) between the first and last calls. That is the time it takes for 1000 * 100 conversions. That will give you an accurate value with minimal overhead, assuming your code doesn't block somewhere else.

    However, there is no reason to doubt what is being stated in the RM, especially without any evidence of it being wrong.

    3 replies

    Super User
    September 18, 2024

    @Aiden_2131 wrote:

    how to export each ADC data to a spreadsheet (csv or xslx files) for further analysis under such high speed? I suppose using Tera Term to log data doesn't work since the maximum baud rate is 921600


    To use UART, you'd have to buffer the data.

    SPI can go faster, if you have some way to "catch" the output.

     


    @Aiden_2131 wrote:

    both of which are less than 1 million, does it make sense?


    Remember that each ADC sample is 12 bits - so, at 1M samples per second (ie, 1 sample every microsecond), you're getting 12M sample bits per second...

     


    @Aiden_2131 wrote:

    CooCox CoIDE.


    Now there's a blast from the past!!

    Explorer
    September 18, 2024

    You don't need a big memmory buffer or high speed usart.

    Simple create  uint16 adc_data[512];

    Run adc with dma, because 1 msps w/o dma is impossible.

    Configure one timer to output 100 kHz PWM, verify by oscilloscope.

    Connect pwm to adc input.

    Inspect adc_data, should be pattern 5 hugh values followed 5 low values. You can send adc_data to wharver you wish, just stop adc , preventing overwriting data. Or install second "double buffer"

    TDKAnswer
    Super User
    September 18, 2024

    > What can I do to test if each conversion is really that fast

    Set up circular conversions to a large internal buffer, say 1000 samples. When the conversion complete callback is called, read the time. Do this for 101 consecutive times and take the difference in time (or system ticks) between the first and last calls. That is the time it takes for 1000 * 100 conversions. That will give you an accurate value with minimal overhead, assuming your code doesn't block somewhere else.

    However, there is no reason to doubt what is being stated in the RM, especially without any evidence of it being wrong.

    Visitor II
    September 26, 2024

    Hi,

    Thanks for your response. It takes some time for me to study the peripherals of MCU. Does your method imply that DMA frequency is the same as the frequency of ADC? While I look at my code and test DMA inturrupt, I feel like the frequency of DMA is at around 15.6kHz, which, I suppose, is because it's set by TIM1 (but I'm not sure).

    How do I set the DMA registers so that DMA works in sync with ADC frequency? In this case, DMA is triggered whenever there's a new conversion data available in ADC DR register, is it correct? 

     

    Super User
    September 26, 2024

    The DMA works on-demand. When the ADC says data is ready, it sets a flag and the DMA will shift it into memory.

    The speed of the DMA is much faster than the ADC. There are no DMA speed settings required.