Ground Embedded KO Subscribe

3D Labs

PWM Duty Cycle

Change duty cycle and frequency and watch the waveform, average voltage and STM32 timer settings (PSC, ARR, CCR) together.

Controls

Results

Average voltage
Period
On time
Motor speed (model)

STM32 timer settings 72 MHz

PSC
ARR
CCR
Duty resolution

Try this

  1. Move the duty cycle. The LED brightens and the motor fan speeds up. The blue dashed line on the scope is the average voltage.
  2. Press Slow motion on. The PWM period becomes one second, so you can see the LED switching on and off and the motor turning in bursts.
  3. Turn slow motion off and it looks smooth again: your eye and the motor's inertia average the fast flicker.
  4. Change the frequency and PSC and ARR change with it. The larger ARR is, the finer the duty steps (duty resolution).

How it is calculated

PWM frequency = timer clock / ((PSC + 1) × (ARR + 1))
Duty cycle    = CCR / (ARR + 1)

ARR tops out at 65535 on a 16-bit timer. When a low frequency would push ARR past that, PSC is raised to divide the timer clock first. The simulation keeps ARR as large as possible, because a larger ARR gives finer duty control.

FREE PDFGet the 3 free ebooksIf you want what you just ran written down: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →

This lab is also available in Korean. More labs: all 3D labs.