cancel
Showing results for 
Search instead for 
Did you mean: 

ADC and TIMer callbacks

VidhiPa
Associate II

Hi Can anyone help me understand the difference between

a) writing control loop and obtaining ADC values in HAL_ADC_ConvCpltCallback with ADC ISRs

instead of

b) writing control loop and obtaining ADC values in HAL_TIM_PeriodElapsedCallback using TIMER ISRs,

from callbacks perspective. 

how it can affect CPU utilization and performance by using different callbacks ? 

any link to the document for understanding the same would be appreciated. 

Notes: I am working with STM32G4, I have ADC conversion with DMA. ADC ISR is running at 18 times higher frequency than that of TIMER ISR.

Thank you !

 

 

6 REPLIES 6
STTwo-32
ST Employee

Hello @VidhiPa 

I suggest you to take a look at the ADC structure and configuration of this example, it may be helpful

PS: dont forget to read the readme file of the project.

Best Regards.

STTwo-32 

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.

I will take a look, but I would appreciate if can you tell me something about my enquiry. Thanks

TDK
Guru

From a performance standpoint, using the DMA half- and full-complete callbacks is generally going to be the most efficient, as it will be called the least.

Timer period over doesn't necessary mean ADC data is ready.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for that information. 

Are there any criteria or important thing to be kept in mind while using callbacks other than your comment ?

are there any links to useful information on this topic ?

Keep callbacks short, and keep the callback frequency as low as you can, and generally to a max of tens of kHz. Note that callbacks take time to execute, and trying to call them more often that they take to complete will result in bad behavior.

Doesn't really matter which callback you use in terms of performance, but since you're processing ADC data here and using DMA to move it, the relevant callback is the DMA transfer complete callback. The other ones don't necessarily correspond to data being available to process.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you!