cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 ADC using timers

GHARI.1
Associate II

Hello,

I am using Nucleo-H743ZI ,I am using timer1 to trigger ADC.

My APB1 clock frequency is 240MHz and my ARR register is 240 of timer 1. So my sampling rate of ADC should be 1Msamples/sec. To check it I am toggling a pin whenever ADC conversion complete is done.

Instead of 1Msamples/sec I am getting around 250Ksamples/sec what might be the issue.

For low PWM frequency the relation (TIMER1_freq=APB1_frequency/ARR) is working fine as I decrease ARR my PWM output is not following above formulae.

Can anyone help me out what might be the issue?

1 ACCEPTED SOLUTION

Accepted Solutions
Maybe I answered too quickly.
You would use the TRGO event to trigger the ADC. It’s unclear what “using timer 1�? to trigger the adc means. If you are triggering it within the interrupt, that is not going to work at 1 Msps. The TRGO event doesn’t using the cpu to trigger it.
Use DMA to send the result to memory directly without cpu intervention. Process data in a half or full transfer complete interrupt.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

13 REPLIES 13
TDK
Guru

Your processor does not have infinite power. Trying to call an interrupt at 1 MHz is overloading the system and it can't keep up.

> TIMER1_freq=APB1_frequency/ARR

The equation, at least in how it relates to ARR, is actually:

> TIMER1_freq = APB1_frequency / (ARR + 1)

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

Then how should I trigger ADC to get 1 Mega samples/sec​

The same way you are now. Just don’t enable the interrupt.
If you feel a post has answered your question, please click "Accept as Solution".
Maybe I answered too quickly.
You would use the TRGO event to trigger the ADC. It’s unclear what “using timer 1�? to trigger the adc means. If you are triggering it within the interrupt, that is not going to work at 1 Msps. The TRGO event doesn’t using the cpu to trigger it.
Use DMA to send the result to memory directly without cpu intervention. Process data in a half or full transfer complete interrupt.
If you feel a post has answered your question, please click "Accept as Solution".

I didn't get you what you meant to say is that "Instead of timers to trigger adc use dma without cpu intervation" so that I can achievw high sample rate. Am I right correct me If I am wrong.

I'm not sure what you're asking.

Use a timer to trigger ADC conversions on the TRGO event. Use DMA to transfer that information directly to memory. The HAL_ADC_Start_DMA will be used to start the process.

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

When dma runs in circular mode, you have array in memory which is contantly overwritten by the new data from ADC. This process does need any function calls from main loop and runs endlessly after ADC is started incircular DMA mode. Now, if you enable DMA half complete and complete interrupts, ​you have information about which part of memory just have ben overwritten. At high sampling rates you must act fast, either perform some light-weight computstions, or copy recently filled array halves to a safe memory location for further processing. If you perform some heavy processing inside interrupt data may be overwritten before even being processed. In those interrupts you can call memcpy or use mem2mem tranfer. Enable circular DMA mode, call simgle function to start ADC in DMA mode and insert code for HAL_ADC_ConvHalfCpltCallback and HAL_ADC_ConvCpltCallback callback functions in main.c

Disappointed with crowdfunding projects? Make a lasting, meaningful impact as a Tech Sponsor instead: Visit TechSponsor.io to Start Your Journey!

@TDK​  Using this technique will I be able to achieve 1Msamp/sec data rate?

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