Skip to main content
Associate II
November 20, 2023
Question

ADC and TIMer callbacks

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 !

 

 

This topic has been closed for replies.

6 replies

STTwo-32
ST Technical Moderator
November 20, 2023

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.
VidhiPaAuthor
Associate II
November 20, 2023

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

TDK
November 20, 2023

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""."
VidhiPaAuthor
Associate II
November 21, 2023

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 ?

TDK
November 21, 2023

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""."