Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 292 of 9364. Peripheral Interfacing and ControlFree lesson

Managing PWM Frequency for Efficient Motor Drive

Students will adjust timer prescalers and period registers to select optimal switching frequencies that minimize noise and maximize motor efficiency.

In this lesson, you will learn how to fine-tune your timer settings to select an optimal PWM frequency that balances motor efficiency with audible noise reduction.

When driving a motor using Pulse Width Modulation (PWM), the frequency at which you switch the power transistors (the "switching frequency") is critical. If your frequency is too low (e.g., under 20 kHz), the motor coils may vibrate at that rate, creating an annoying, high-pitched whine. However, if the frequency is too high, your transistors will spend more time in their "transition" phase—switching between fully on and fully off—which generates significant heat and reduces your overall power efficiency.

To manage this, we manipulate two primary registers in our hardware timer: the Prescaler and the Auto-Reload Register (ARR).

The PWM frequency is calculated as: Frequency = Timer_Clock / (Prescaler + 1) * (ARR + 1)

By increasing the Prescaler, you slow down the clock signal reaching the timer counter. By increasing the ARR, you extend the time the timer takes to reach its overflow point, which resets the PWM cycle.

Consider this conceptual configuration:

// Target: Reduce PWM frequency to eliminate noise
// Assuming Timer_Clock is 84MHz

// Increase Prescaler to slow down the timer base frequency
TIMx->PSC = 83; // Prescaler: Divide clock by 84 (84MHz / 84 = 1MHz)

// Adjust ARR to set the period (e.g., 50µs period = 20kHz frequency)
TIMx->ARR = 49; // 1MHz / 50 = 20kHz

By adjusting these two values, you can push the switching frequency just above the range of human hearing (20 kHz) to keep the motor silent, while keeping it low enough to prevent excessive switching losses in your driver hardware. If the motor runs hot, try lowering the frequency slightly; if it whines, increase the ARR or Prescaler values to hit that "sweet spot" where the motor runs smooth, cool, and silent.

Key Takeaway: Balancing your PWM frequency involves adjusting the Prescaler and ARR registers to remain above the audible threshold while minimizing switching losses to ensure peak motor efficiency.