2
votes

I use ADC with DMA (STM32F4, ide STM32CubeIDE) and I think that I understand how it works but still have one dilema. From my understanding MCU is called only when DMA transfer is completed, basically MCU go into this function when DMA ADC is finished

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Is that right?

So if this is true, I have next dilema: for example adc_clock is 10MHz, sample time is 480 adc_cycles, 12 bit adc resolution. adc_sample_period = 1/10Mhz * (480 + 12 + 3) = 49.5uS. That mean MCU will go into HAL_ADC_ConvCpltCallback() every 49.5uS ??? For my perspective that is hard intensive, especially in bigger projects. Did anyone have idea how to solve this "problem"? I want to read ADC results for example every 1mS but also want to implement DMA into ADC. Any idea is welcome

2
You need to start with a spec. What are you to do with the ADC values, what resolutions and real-time deadlines are actually needed and so on. It doesn't make sense to catch every ADC conversion at high clock speed if you don't need to decode a signal in hard real-time.Lundin
@Lundin I know what I will do with adc values. It will be used in formula to calculate current. Resolution is 12bit (0-4095) , I emphasize that in text above. I agree with constatation that reading adc every is 49.5uS is wastaing of MCU resources. I need adc valuse every 1mS, maybe to engage timer to triger ADC DMA?subavet995
Start by turning down the ADC conversion clock?Lundin
Min adc clock is 5Mhz. (APB2 / add_prescaler) = (40Mhz / 8) = 5Mhz. So 1/5Mhz*(480 + 12 + 3) = 99uS which is too hard intensive for my perspective. I will try will timer, I will report resultssubavet995

2 Answers

2
votes

Read the uC documentation - do not start from the "magic" HAL functions.

1ms period between the the ADC conversions is absolutely nothing. I have many projects where I use double or triple ADC modes with resulting sampling rate of 18MSPS.

Generally speaking if you want poor, slow, inefficient and working "by accident" code - use HAL. Otherwise learn your hardware and use registers instead.

0
votes

This is how I solve this problem: I change DMA configuration. DMA was configurated to work in circular mode, that mean when ADC finish one conversion DMA store data and MCU is notified via

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Basically MCU was notified every 49.5uS and for my purpose that was too intensive (I need ADC result every 1mS). I create timer which is used to indicate ADC when need to start sample and with DMA in normal mode (ADC will do only 1 measurement) that solve my problem. Every 1mS got result from ADC. So trick was in DMA modes (circular/normal mode).