cancel
Showing results for 
Search instead for 
Did you mean: 

A question on use timer and samples out

Daddi
Associate

Good morning everyone,
I'm at my first experience with STM and between guides and tutorials I'm learning many things.
But I wanted to configure a 32bit TIM5 timer on my STM32F446 board, I would like my timer to calculate a sample every 0.000001s, only if I configure the timer I expect 1000000 samples to correspond to a second, but the timer output seems different .

Additionally if I configure the timer to 0.00001 sample at 100000 samples it gives me the correct result per second.

For the TIM5 calculations I ran Prescale 1 and Overflow at 41 with 84MHz sampling time, it doesn't work.

Conversely, if I set OverFlow to 419 I can get the correct timer but with fewer samples.

I need a sample every 0.000001s, where am I wrong?

I hope I was clear enough, happy new year to all of you.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The processor has limited resources. Trying to call something at 1 MHz is likely to fail as the processor can't keep up. The result is that the thing you want to happen still happens, but at a reduced rate. Interrupts should generally be limited to tens of kHz, although you can get much higher with simple and highly code-optimized solutions.

Consider alternative solutions. If you're trying to use the ADC, for example, you can use DMA to remove the CPU requirement from the equation.

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

View solution in original post

2 REPLIES 2
TDK
Guru

The processor has limited resources. Trying to call something at 1 MHz is likely to fail as the processor can't keep up. The result is that the thing you want to happen still happens, but at a reduced rate. Interrupts should generally be limited to tens of kHz, although you can get much higher with simple and highly code-optimized solutions.

Consider alternative solutions. If you're trying to use the ADC, for example, you can use DMA to remove the CPU requirement from the equation.

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

What kind of "samples" ?

You can use the TIM to trigger the ADC which will then have DMA save the value to an array. The length of the array can decimate the interrupt loading.

You could also use a TIM to trigger a DMA transfer directly, copying the values from a bank of GPIO pins, again into an array. When the array fills, or half-fills can can get an interrupt to process the inactive half of the buffer.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..