PWM Frequency Calculator: Timer, Prescaler & TOP to Hz

PWM Frequency Calculator

Compute PWM frequency from a timer clock, prescaler and TOP register with f = f_clock / (prescaler x (TOP + 1)), get the PWM period and the duty resolution in bits and steps, or switch to solve mode to find the TOP value that hits a target frequency on an 8, 10, 12 or 16-bit timer.

🔌Choose a Mode

🎯Real MCU Timer Presets

📝Timer Inputs

Clock feeding the timer before the prescaler.

Applies to the clock frequency field.

Counter ticks at clock divided by this value.

Sets the maximum allowed TOP value.

Counter reloads at TOP; period is TOP + 1 counts.

Desired output frequency to solve TOP for.

Applies to the target frequency field.

Controls rounding on every result card.

PWM Frequency 0 Hz output switching rate
PWM Period 0 s time for one full cycle
Duty Resolution 0 bits duty steps available
Required TOP 0 counts per period

🔢Formula Snapshot

fclk / (ps (TOP+1))
T1 / f_pwm
bitslog2(TOP + 1)
TOPclk / (ps f) − 1

📋Prescaler and TOP to Frequency (16 MHz clock)

PrescalerTOPCounts (TOP+1)PWM FrequencyReads As
1999100016.00 kHzFast motor PWM
1199920008.000 kHzAudible whine gone
179980020.00 kHzUltrasonic drive
16553565536244.1 HzFull 16-bit LED
82552567.813 kHz8-bit fast PWM
849995000400.0 HzCoarse dimming
649991000250.0 HzSlow LED fade
2561249125050.00 HzRC servo pulse

📊Timer Bit Width and Duty Resolution

ResolutionTOP MaxCounts MaxDuty Steps at Full TOPDuty Bits
8-bit255256256 steps8.00 bits
10-bit102310241024 steps10.00 bits
12-bit409540964096 steps12.00 bits
14-bit163831638416384 steps14.00 bits
16-bit655356553665536 steps16.00 bits
32-bit42949672954.29 billionVery fine32.00 bits

🧩Common MCU PWM Configurations

PlatformClockPrescalerTOPResulting Frequency
Arduino Uno pin 5/616 MHz64255976.6 Hz
Arduino Uno pin 9/1016 MHz125562.50 kHz
STM32 general timer72 MHz729991.000 kHz
STM32 motor PWM72 MHz1359920.00 kHz
ESP32 LEDC channel80 MHz1163834.883 kHz
ATmega servo Timer116 MHz83999950.00 Hz
RP2040 PWM slice125 MHz1259991.000 kHz

📏PWM Period and Frequency Conversions

FrequencyPeriodPeriod in msTypical Use
50 Hz0.02 s20 msRC servo, mains AC
490 Hz0.00204 s2.04 msArduino default PWM
1 kHz0.001 s1 msGeneral LED dimming
20 kHz0.00005 s0.05 msSilent motor drive
25 kHz0.00004 s0.04 msPC fan control
100 kHz0.00001 s0.01 msSwitching supply

🗃Frequency, Prescaler and TOP Comparison Grid

ClockPrescalerTOPPWM FreqPeriodDuty Bits
16 MHz199916.00 kHz62.50 us9.97 bits
16 MHz83999950.00 Hz20.00 ms15.29 bits
16 MHz64255976.6 Hz1.024 ms8.00 bits
72 MHz1359920.00 kHz50.00 us11.81 bits
72 MHz729991.000 kHz1.000 ms9.97 bits
80 MHz1159995.000 kHz200.0 us13.97 bits
80 MHz1799100.0 kHz10.00 us9.64 bits
125 MHz1259991.000 kHz1.000 ms9.97 bits
48 MHz1191925.00 kHz40.00 us10.91 bits
168 MHz1655352.563 kHz390.1 us16.00 bits

Formula Breakdown

f_pwm = f_clk / (ps (TOP+1))PWM frequency is the timer clock divided by the prescaler times the number of counts. At 16 MHz, prescaler 1, TOP 999: f = 16000000 / (1 x 1000) = 16000 Hz.
Period T = 1 / f_pwmThe period is the reciprocal of frequency. A 16 kHz PWM has T = 1 / 16000 = 0.0000625 s, or 62.5 microseconds per cycle.
Counts = TOP + 1The counter runs from 0 up to TOP inclusive, so one full period spans TOP + 1 ticks. This off-by-one is why TOP 999 gives 1000 counts, not 999.
Duty bits = log2(TOP + 1)Duty resolution is the base-2 log of the count total. TOP 999 gives log2(1000) = 9.97 bits, so just under a clean 10-bit duty cycle.
Solve TOP = f_clk / (ps f) − 1Rearrange for the register. To hit 20 kHz at 72 MHz with prescaler 1: TOP = 72000000 / (1 x 20000) − 1 = 3599.
Overflow check TOP ≤ 2^N − 1A solved TOP must fit the timer width. On a 16-bit timer the limit is 65535; exceed it and you must raise the prescaler or lower the clock.
Prescaler roleThe prescaler divides the input clock before the counter. Larger dividers reach lower frequencies but coarsen each tick, trading range for duty resolution.

💡PWM Tuning Tips

Push motor PWM above hearing: A DC motor driven at 490 Hz often produces an audible whine. Move the frequency to 20 kHz or higher and it drops out of the human hearing range. At 16 MHz with prescaler 1, set TOP to 799 for exactly 20 kHz, which still leaves about 9.6 bits of duty resolution for smooth speed control.
Balance frequency against resolution: For a fixed clock, raising the frequency lowers TOP and cuts duty steps. At 16 MHz targeting 50 kHz with prescaler 1, TOP is only 319, giving roughly 8.3 bits. If you need both high frequency and fine control, pick a faster clock instead of a bigger prescaler.

If you’ve worked with an Arduino hooked up to a motor, then you know that the resulting high-pitched whine sounds like this: You control how long it’s on (the duty cycle). However, it is hard to hear anything else because PWM frequency is in the range humans can hear. To fix this, we don’t need to guess at what code will work; instead, we can learn about the timer peripheral arithmetic.

All microcontrollers produces PWM by counting up from zero until they reaches a maximum number and start over. How fast does this happen? The answer is based off three variables: This is the clock source. The prescaler It’s a simple formula, but in practice, most folks does it wrong.

How to Fix Motor Noise with Math

It turns out that they forgot that counter values begins at zero. They also forgot about that pesky one added to the top value. The result is one thousand ticks for a top value of nine hundred and ninety-nine. That one tick throws off frequency calculation unless you remember to add it back in.

When you’re trying to hit a precise target such as twenty kilohertz for a silent motor drive or fifty hertz for an RC servo, this get compounded. A prescaler acts as a dividing chip between the counter and the system clock. It chops up the input rate at which it counts. If you have a big enough counter register to count all the way to 0 before overflowing, then a large prescaler will bring those rates down even more. But now each “tick” on the counter is a less precise measure of time. Your step-duties gets chunky. You can’t finely control your speed or brightness anymore.

A smaller prescaler gives higher resolution but requires a very high number in the top counter register to achieve same slowdown. That’s where a calculator comes into play. You plug in how fast your chip runs and how slow you want it to tick. Instead of fiddling with algebra when you’re debugging, it give you the right top value without any work.

To make your STM32 run at twenty kilohertz from its seventy-two megahertz crystal, you’d set the top register to three thousand five hundred and ninety-nine (which is exactly what math says). And if it’s larger than your timer can handle, it’ll let you know that, too. Is it eight bits at most? An eight-bit timer maxes out at two hundred fifty-five. Anything higher than that, and you’ll get overflows or something goofy happening until you change the prescaler or switch chips.

Sometimes more than just frequency is important; resolution is also critical in many situations. An eight bit resolution on an LED dimmer can show banding that’s visually objectionable when you’re looking for gradient subtlety. Sixty-five thousand different steps is smoother, now we’re using a sixteen-bit timer. At high frequencies, however, it takes some attention to make sure you keep the upper register dense enough and still have that full range of steps. For all combinations, the tool displays actual duty resolution (in bits) achieved. Does the increased prescaler makes the reduced resolution worthwhile?

Preset is typically where real world tuning begins. A standard servo timing preset or an Arduino PWM is familiar to most engineers. They are good starting points as they compensate for internal clock dividers and crystal oscillators that is used in commonly available boards. From there one tweaks one variable and sees what happens. Often lowering the frequency reduce noise but raises the top value. This impacts the number of discrete level it can be controlled by.

All of this comes back to PWM configuration: it’s one of those balance-a-few-competing-constraints problems. You want a high enough frequency that it won’t be heard or visible as flickering light. You also want a frequency or resolution high or low enough that the motor still move smoothly. And then there are the register values… You’d like something that sits well inside the operating range for your hardware.

When you make the three quantities (clock, prescaler, top value) explicit, you no longer guess at their values; you design them. Once the numbers come out right, the room ceases its whining. Now all you hear is the quiet hum of efficient power delivery. You should of used a calculator sooner to avoid the moddern issues. Actualy, it would of helped with the luxurios setup.

PWM Frequency Calculator: Timer, Prescaler & TOP to Hz