Arduino Timer Frequency Generation Limits

1 post / 0 new
Runtime Micro's picture
Runtime Micro
Joined: 07/24/2016 - 9:18am
Arduino Timer Frequency Generation Limits

Please Note: RTM_TimerCalc V1.3 provides all the info in the Chart at bottom and way more. Just saying...

RTM_TimerCalc helps you explore Arduino Timer Frequency generation for Nano, Uno and Mega2560 boards. Each MCU has Timers you can use to create PWM or variable frequency signals.

However, there are several important problems using these Timers for frequency generation;

  • Frequency Gaps -- numerous unreachable frequencies between frequency steps.
  • Range Limits -- maximum and minimum frequencies the hardware cannot exceed.

Arduino Timer Frequency Gaps

Alhough Timer outputs cover a wide range of frequency, one must realize there are unavoidable gaps between those frequencies. These gaps may limit usefulness of an Arduino frequency generation project!

For example, you may wish to generate 12 MHz from your 16 MHz Arduino. Unfortunately, your Arduino Timer can only divide the clock by an Integer value.

Test for Fraction Method

To see if your Arduino has any chance of generating a particular frequency, just divide the Clock by the desired frequency. If you get a fraction, it won't work (at least not without some sort of OFFSET).

  • EXAMPLE: If you take 16 MHz and divide by 12 MHz, you get a fraction -- (16 / 12 =  4 / 3 = 1.3...).

So, we can't get a 12 MHz output for a 16 MHz Arduino using a Timer or divider scheme. The closest we can come is 8 MHz (dividing by 2 -- an Integer).

Because of the integer-only divide problem, frequency gaps exist across the entire generation range! That's part of why RTM_TimerCalc tests if the frequency you requested is the same as what was calculated. If any difference exists, you're given a warning and shown the error (called out as OFFSET).

Image shows frequency gap error at frequency requested.

This often means generating a signal close to the desired frequency, but missing by some amount of error. One way around is change the Arduino's clock crystal. But there are other frequency generation problems to watch for.

Arduino Timer Frequency Limits

Since we have a fixed clock, the Timer and Pre-Scaler can only generate a fixed number of frequencies. Maximum and Minimum frequency define the overall output range.

The highest and lowest frequencies are determined by the Clock, Pre-Scaler and size of the Timer in bits (8-bit VS 16-bit). The 16 bit Timer can generate far more frequencies and reach down to sub-audio range. The 8-bit has much less capability.

Here's a (corrected 3-10-2021) table showing Maximum and Minimum output Frequencies. It covers 8 and 16 bit Timers for Nano, Uno and Mega2560 running at 16 MHz. It also shows periods relative to frequency limits.

Image shows Table of Arduino Timer Frequency Generation Limits.

This table reveals the longest and shortest Periods possible. And the highest and lowest Frequencies you can attain (clocking at 16 MHz).

Of course, I'm only looking at output modes you can select using the RTM_TimerCalc application.

Remember, RTM_TimerCalc lets you spot Gap-Frequencies and tells you the amount of OFFSET to expect. Sometimes the error is so small its not an issue. Other times the OFFSET is huge. Its up to you to decide if the numbers make sense for your project.