PWM Duty Cycle
Change duty cycle and frequency and watch the waveform, average voltage and STM32 timer settings (PSC, ARR, CCR) together.
DUTY30%Avg 0.99 V
Turn on slow motion to watch the PWM switch on and off once a second
Loading the 3D scene
Controls
Results
- Average voltage
- Period
- On time
- Motor speed (model)
STM32 timer settings 72 MHz
- PSC
- ARR
- CCR
- Duty resolution
Try this
- Move the duty cycle. The LED brightens and the motor fan speeds up. The blue dashed line on the scope is the average voltage.
- 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.
- Turn slow motion off and it looks smooth again: your eye and the motor's inertia average the fast flicker.
- 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.
This lab is also available in Korean. More labs: all 3D labs.