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
Although 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).duino timers can't divide by fractions! But 8 Mhz is possible (16 / 8 = 2 divider). And 4 MHz is possible (16 / 4 = 4 divider). But (again) 6 MHz is not possible as it requires a fractional divide (16 / 6 = 2.666... fraction problem).
Because of the integer-only divide problem, frequency gaps exist across the entire generation range! That's why RTM_TimerCalc tests if the frequency you requested is the same as what was calculated. If any difference exists, you're shown the value (called out as OFFSET).
This often means generating a signal near the desired frequency but missing it by some amount of OFFSET. One way around is change the Arduino's clock crystal. But there are other frequency generation problems to watch for.
Arduino Timer Limits (Frequency and Interval)
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.
Older versions of RTM_TimerCalc only warned you if you went beyond the possible Frequency (or Interval) range. This was followed by a suggestion to check your parameters. Not much help...
But TimerCalc versions 1.3x and beyond offer a new way to look at Limits and Error messages. The idea is generate a limits-range based on current parameters. If your 'Ask' went too far, you are shown a message like the following;
Taking this limits-range calculation a step further, we can view a detailed report of Limits by clicking the "Limits" button. The following Image shows a typical Limits Report for current parameter selections.
This report shows the longest and shortest Periods possible along with highest and lowest Frequencies.
Remember, RTM_TimerCalc lets you spot Gap problems and tells you the OFFSET to expect. It helps you investigate Limits of the hardware for parameters you selected.
Whether you're a Noob or an expert, this information can be helpful. Its always good to know your numbers.