2024-01-01 09:49 AM
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.
Solved! Go to Solution.
2024-01-01 10:04 AM - edited 2024-01-01 10:04 AM
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.
2024-01-01 10:04 AM - edited 2024-01-01 10:04 AM
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.
2024-01-01 10:09 AM
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.