cancel
Showing results for 
Search instead for 
Did you mean: 

How to Achieve 0.1 Hz Resolution from 0 to 10 kHz Using STM32 Timer?

Sansel
Associate

 

Hi everyone,

I'm trying to generate output frequencies from 0 Hz to 10,000 Hz using STM32F407VET6 with Timer2 in Output Compare Toggle Mode. The timer clock is 84 MHz.

I need to achieve:

  • 0.1 Hz resolution up to 10 kHz

  • Ideally, also support 0.001 Hz resolution at lower frequencies

The problem is that at higher frequencies, the formula:

f_out = f_timer / (2 * ARR)
often results in a non-integer ARR. For example, to generate 9999.9 Hz, I get:

 

ARR = 84,000,000 / (2 * 9999.9) ≈ 4200.042

But since ARR must be an integer, I have to use 4200, which gives 10,000 Hz — a 0.1 Hz error.


i am using DDS (Direct Digital Synthesis) using a phase accumulator in software
With DDS, I can theoretically achieve very fine resolution, but when I measure the output using a CRO (oscilloscope), I notice jitter in the waveform.

Question:
How can I generate accurate frequencies with 0.1 Hz resolution across the full range (up to 10 kHz)?
Are there any techniques (e.g., fractional timers, clock tricks, advanced modes, combining timers) to overcome this limitation?

2 REPLIES 2
TDK
Guru

No, you can't have fractional ticks here. On STM32H7, you could adjust the PLL clock fractionally to achieve this.

You could set up DMA to update the ticks so that the average frequency is as desired, but there will be jitter of up to 1 tick.

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

Like TDK said if you cannot get the exact frequency you want using an integer period at your specific timer clock you can adjust your PLL and/or timer clock and/or clock source. Or live with jitter (switches between 9997.6Hz and 10000.0Hz to create 9999.9Hz on average).

9999.9Hz +- .1 Hz -> 10ppm
9999.9Hz +- .01 Hz -> 1ppm
so you would need very precise clock source to get an accuracy that is in the same ballpark as your resolution.

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.