2024-04-26 06:27 AM
2024-04-29 07:07 AM
Hello,
if I understand right to your problem, program need to read data from ADC and at the same time need to compute some data. For this need there is a DMA which can transfer data from ADC to memory independently on the running program:
Getting started with ADC - stm32mcu
Also in your code MCU is computing average of ADC results in program. That can be partially replaced by using longer sampling time in ADC settings and reduce CPU load.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-04-30 04:57 AM - edited 2024-04-30 04:59 AM
Hi @Hl_st
Thank you for your response. I have tried as you say by using DMA and using longer ADC sampling time. But it is taking more time.
As I am using STM32F030F4P6 its clock frequency is 48MHz and 12 bit ADC. It can read ADC up to 1 Mbps.
I want to read at 166ksps first I was using timer trigger of 6.024 to read adc in that I am getting 166K adc sample at 1 sec but after adding averaging calculation it is giving data after 2 sec.
is it possible to read adc calculation output at 1 sec ?
Here I am attaching the DMA ADC code that you have suggest. Please review if I am doing something wrong.
2024-05-13 06:39 AM
Hello,
you can try to configure DMA in circular mode and ADC using timer trigger, it will be continuously transferring adc results into the buffer. If the buffer will be for example for 16 values, program can pooling in while loop and based on DMA position in the buffer (DMA1_Channelx->CNDTR) can compute average from every last 8 values. So the code should looks like this:
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.