PWM Timer Prescaler & Period Solver (Arduino/STM32)

← Back to Engineering Library

Setting up a microcontroller timer for a specific PWM frequency comes down to choosing two integer values in your timer’s registers: the prescaler (PSC) and the auto-reload register (ARR). Those two numbers, multiplied together, scale your system clock down to your actual PWM output frequency. If you get the math wrong, you’ll see the effects right away—your motor won’t run at the intended speed, LEDs will flicker or dim unevenly, or your servo won’t get the pulse width it expects. This PWM Timer Prescaler & Period Solver lets you quickly figure out the most practical PSC and ARR values based on your clock speed, the exact PWM frequency you want, and the bit-width of your timer. Pick the right values if your application genuinely depends on specific switching rates, like motors, lighting, or servos. Below you’ll find the working equations, an example calculation, a breakdown of the technical background, and an FAQ.

What is a PWM timer prescaler?

A PWM timer prescaler is just a divider that slows the raw microcontroller clock down before it reaches your timer hardware. Without it, your timer would run too fast for most useful PWM output, making it extremely difficult to set slower, more functional PWM frequencies for things like motor speed or LED dimming.

Simple Explanation

Picture the microcontroller’s main clock as clicking away millions of times per second—way faster than any actuator can physically respond. The prescaler is a downshift: it divides that clock down to more manageable speeds, which the timer then counts. The timer counts up to the ARR value; once it hits that, the counter resets, and that full cycle determines your PWM frequency.

📐 Browse all 384 free engineering calculators

PWM Timer Configuration Diagram

PWM Timer Prescaler & Period Solver (Arduino/STM32) Technical Diagram

PWM Timer Prescaler Calculator

Engineering calculation notice

This calculator is intended for education, concept evaluation, and preliminary design. Results are based on the equations and assumptions described on this page, but cannot account for every real-world load case, tolerance, material property, environmental condition, installation detail, safety factor, code, or regulatory requirement. Verify all inputs, assumptions, units, and results independently before selecting components or using the result in a real application. Safety-critical, structural, medical, lifting, transportation, or regulated applications must be reviewed by a qualified engineer.

Found a calculation error? Message us

📹 Video Walkthrough — How to Use This Calculator

PWM Timer Prescaler & Period Solver (Arduino/STM32)

How to Use This Calculator

  1. Enter your microcontroller's clock frequency in Hz (e.g., 16000000 for a 16MHz Arduino Uno).
  2. Enter your desired PWM output frequency in Hz (e.g., 1000 for 1kHz motor control).
  3. Select your timer resolution — 8-bit (0–255) or 16-bit (0–65535) — from the dropdown.
  4. Click Calculate to see your result.

PWM Timer Prescaler & Period Solver Interactive Visualizer

This tool shows what happens to PSC (prescaler) and ARR (auto-reload register) in real-time as you change your clock frequency, target PWM frequency, or timer bit-width. It’s a straight visual take on how these numbers relate on Arduino and STM32 timers.

Clock Frequency 16 MHz
Target PWM Freq 1000 Hz
Timer Resolution

PRESCALER (PSC)

1

PERIOD (ARR)

15999

ACTUAL FREQ

1000 Hz

FIRGELLI Automations — Interactive Engineering Calculators

Mathematical Formulas

Here are the main equations you’ll use to size your PWM timer’s ARR value and to check the real output frequency you’ll get.

Core PWM Timer Equations

Period Register Calculation:
ARR = (fclock / (PSC × fPWM)) - 1
Actual PWM Frequency:
factual = fclock / (PSC × (ARR + 1))
Duty Cycle Resolution:
Resolution = ARR + 1 steps
Frequency Error:
Error% = |((factual - fdesired) / fdesired)| × 100

Variable Definitions:

  • fclock = System clock frequency (Hz)
  • PSC = Prescaler value (1 to 65536)
  • ARR = Auto-Reload Register value (Period)
  • fPWM = PWM output frequency (Hz)

Simple Example

Arduino Uno (16MHz clock), 1kHz PWM, 16-bit timer:

  • PSC = 1
  • ARR = (16,000,000 / (1 × 1,000)) − 1 = 15,999
  • Actual frequency = 16,000,000 / (1 × 16,000) = 1,000 Hz (exact)
  • Duty cycle resolution = 16,000 steps

Understanding PWM Timer Configuration

How PWM Timers Work

PWM timers are basic building blocks in microcontroller setups when you need repeatable, adjustable output pulses. The prescaler and period values set the pace. Proper calculation gives you the output frequency and duty step size you need without wasting resolution or missing timing.

The timer hardware simply counts up from zero to ARR, resets, and repeats. There’s also a Compare Register (CCR) in play—the output stays high while the count is under CCR, then goes low. That’s your variable-width pulse, and the ratio CCR/ARR sets duty cycle.

The Role of Prescalers

The prescaler sits between your fast system clock and the timer. If you try to feed a 16MHz (or higher) system clock straight to the timer with no prescale, PWM cycles will be much too fast for most motors, LEDs, and servos. The prescaler value slows things down, letting you get practical PWM rates and more useful resolution.

For instance, at 16MHz and PSC = 1, an 8-bit timer only lets you reach about 62.5kHz max. Not a problem for RF work, but no good for motors, which usually run at several kHz, not tens of kHz.

Timer Resolution Considerations

The bit-width of your timer (8-bit, 16-bit) sets your options. An 8-bit timer tops out at 256 steps; a 16-bit timer gives you a lot finer control—up to 65,536 steps. That extra resolution gives you smoother output and makes a difference in sensitive motor or LED control.

That higher resolution doesn’t come for free. If you want fine control and a reasonable update rate, your prescaler (or possibly your system clock) will need to be set appropriately, or the cycles will take too long. Use the equation: PWM_frequency = Clock_frequency / (Prescaler × (Period + 1)).

Practical Applications

In motion systems—linear actuators, for example—accurate PWM frequency and enough duty resolution are both important. Motor controllers often run 1kHz–20kHz: low enough not to swamp a power stage, high enough to avoid audible whine and get a smooth response. For LED dimming, you may want even higher PWM rates to prevent visible flicker or camera banding, but don’t go so high that you lose dimming steps or waste power in switching losses. Resolution drives smoothness in both cases.

Worked Example

Suppose you want to control a standard hobby servo on an Arduino Uno (16MHz clock) at 50Hz using Timer1 (16-bit).

Given:

  • Clock frequency: 16,000,000 Hz
  • Desired PWM frequency: 50 Hz
  • Timer resolution: 16-bit (0-65535)

Calculation:

First, figure out the total clock cycles per PWM period:

Total cycles = 16,000,000 Hz ÷ 50 Hz = 320,000 cycles

A 16-bit timer tops out at 65,535. So, you’ll need a prescaler:

Minimum prescaler = 320,000 ÷ 65,535 ≈ 4.88

Prescaler can only be an integer, so round up: PSC = 8.

Now ARR = (16,000,000 ÷ (8 × 50)) - 1 = 39,999

Check your result:

Actual frequency = 16,000,000 ÷ (8 × 40,000) = 50 Hz (dead on)

Duty cycle resolution = 40,000 steps

Design Considerations and Best Practices

When choosing PSC/ARR, check these points:

Frequency Accuracy: You’re working with integer dividers, so you don’t always get your exact target frequency. The calculator always finds the closest it can given your limits.

Duty Cycle Resolution: More steps means smoother control, but if you want high resolution and a high frequency, you’ll run into timer or prescaler limits. For motors, at least 256 steps serves most bearings well; more is helpful if you want truly silent transitions.

EMC/EMI: PWM creates noise—both audible and electrical. Some frequencies couple into audio lines or RF bands. Choose a frequency high enough to avoid the worst, or if you’re working with audio/video, well above 20kHz is recommended.

Thermal Effects: Higher switching speeds mean more losses in MOSFETs and output drivers. For high power, especially, don’t crank your PWM frequency higher than needed; the heat can creep up fast.

Advanced Techniques

If your microcontroller can do center-aligned (symmetric) PWM, consider it—for some designs this reduces emissions and evens out response. H-bridge motor drivers may need complementary (inverted) PWM with dead time between outputs to avoid shoot-through. Some motion applications will time-shift different PWM channels to avoid all switches toggling at once; it helps spread out power draw and minimize EMI spikes.

Microcontroller-Specific Considerations

On Arduino, check which timer you’re using. Timer0 runs crucial stuff like delay() and millis(), so tweaking it will break standard timing. Timer1 (16-bit) and Timer2 (8-bit) are safer for custom work.

STM32 chips give you much more flexibility: multiple timers, higher resolution, and sometimes even fractional prescalers for tighter control. They’re better suited for complex PWM or high-frequency needs. But with more complexity comes more stuff to double-check.

If you need to change PWM settings often, especially in a real-time control loop, consider pre-calculating the values you need to swap among. Real-time math isn’t always free.

Integration with Motion Control Systems

When you’re controlling actuators that need specific PWM to run correctly, don’t guess. The PWM rate can affect both mechanical performance (smoothness, noise) and electrical efficiency. For systems with encoders or feedback, make sure your PWM frequency doesn’t line up with sampling times—otherwise, you can get aliasing or missed readings.

Frequently Asked Questions

Q: What happens if my desired PWM frequency cannot be achieved exactly?
Q: How do I choose between 8-bit and 16-bit timer resolution?
Q: What PWM frequency should I use for motor control?
Q: Can I change PWM parameters during runtime?
Q: Why does my calculated PWM frequency differ from the measured frequency?
Q: What's the maximum PWM frequency I can achieve?

📐 Explore our full library of 384 free engineering calculators →

About the Author

Robbie Dickson

Chief Engineer & Founder, FIRGELLI Automations

Robbie Dickson brings over two decades of engineering expertise to FIRGELLI Automations. With a distinguished career at Rolls-Royce, BMW, and Ford, he has deep expertise in mechanical systems, actuator technology, and precision engineering.

🔗 Explore More Free Engineering Calculators

Need to implement these calculations?

Explore the precision-engineered motion control solutions used by top engineers.

Share This Article
Tags: