Pulse Width Modulation controls the fraction of time a digital signal remains ON during a repeated switching period. Instead of generating every possible analog voltage directly, the system switches between defined electrical levels and changes the timing.
That simple idea is used in several very different ways. In a motor driver, duty cycle changes effective electrical power. In LED dimming, it changes average light output. In a hobby servo, a repeated pulse width is usually interpreted as a position command rather than as direct power modulation.
Period, frequency, pulse width, and duty cycle
If one PWM cycle has total period T and the signal is high for ton, duty cycle is:
D = ton / T and Duty cycle (%) = 100 × ton / TFrequency is the inverse of period:
f = 1 / TA 1 kHz PWM signal therefore has a 1 ms period. At 25% duty cycle it remains ON for 0.25 ms and OFF for 0.75 ms. At 75% duty cycle the period stays 1 ms, but ON-time increases to 0.75 ms.
Why switching can produce an analog-like physical result
If a load responds much more slowly than the switching period, it effectively averages the energy delivered by the pulses. For a simple resistive load supplied by a voltage Vs, the average voltage of an ideal 0-to-Vs PWM waveform is:
Vavg = D × VsBut the physical response depends on the load. A resistor converts each pulse directly into heat. An LED emits light during each ON interval, and human vision averages sufficiently fast pulsing. A DC motor winding has inductance, so current cannot jump instantly; rotor inertia further smooths the torque into a continuous mechanical response.
Because loads have different electrical and physical time constants, choosing PWM frequency is not arbitrary.
PWM for DC motor control
For a permanent-magnet DC motor, switching the supply with a transistor or H-bridge is a practical way to vary effective armature voltage. Higher duty cycle generally increases average armature current and torque until the motor accelerates to a new operating speed where back EMF and load torque balance the electrical input.
The motor should not be powered directly from a microcontroller I/O pin. The controller generates a logic-level PWM command; a driver stage switches the motor current. The power circuit must also provide a freewheel path for inductive current when the switch turns off.
| Design choice | Why it matters |
|---|---|
| Switching frequency | Too low can create audible noise and large torque ripple; too high increases switching losses and can reduce driver efficiency. |
| Duty-cycle range | Small motors may not start at very low duty cycle because static friction and load torque create a dead zone. |
| Driver current rating | Starting and stall current can be many times normal running current. |
| Freewheel current path | Inductive motor current must continue safely when the switch turns OFF. |
| Supply decoupling and layout | Fast current edges can inject noise into sensors, logic, and communication lines. |
In the aeroponic humidity project, PWM was useful because fan speed was the actuator between the PI controller and the humidity process. The PI algorithm produced a control command; PWM translated that command into switched electrical power for the fan motor.
Current ripple, torque ripple, and switching frequency
During the ON portion of a PWM cycle, motor current tends to rise; during the OFF portion it decays through the freewheel path. The winding inductance determines how quickly current changes. If switching frequency is high relative to the electrical time constant, current ripple becomes smaller.
That does not mean “higher is always better.” Semiconductor switching losses increase with frequency, and some motor drivers have recommended operating ranges. The correct frequency balances acoustic behavior, current ripple, efficiency, driver capability, electromagnetic compatibility, and control resolution.
Hobby-servo pulses are not the same use of PWM
A common hobby-servo example uses a repetition rate around 50 Hz. This deserves a careful distinction.
A hobby servo normally contains its own internal position-control electronics. The external controller sends a repeated command pulse. The pulse width encodes the requested shaft position. A common nominal command uses a frame of roughly 20 ms and pulse widths around 1–2 ms, but real servo ranges vary and may extend beyond those values.
Calling this signal “PWM” is common because pulse width is modulated, but the servo is not simply receiving average motor power from the input pin. The servo electronics measure the incoming pulse width, compare the requested position with its internal feedback potentiometer or sensor, and then drive the internal motor.
Motor-power PWM: duty cycle controls the energy delivered to a power stage. Servo command pulses: absolute pulse width represents a requested position while the servo handles its own motor power internally.
Timer resolution and command resolution
Microcontrollers usually generate PWM from hardware timers. Timer clock, prescaler, and period register determine both frequency and duty-cycle resolution. If the timer counts from 0 to 255, there are 256 discrete duty-cycle steps. A 16-bit timer can support far finer timing, although usable resolution still depends on the chosen period and clock frequency.
This is particularly important for servo commands because small pulse-width changes can correspond to noticeable angular changes. Generating the waveform with a hardware timer is usually more stable than manually toggling an I/O pin in software while other code is running.
Switching noise and electromagnetic compatibility
PWM edges contain high-frequency components even when the base switching frequency is modest. Long motor wires, poor grounding, and large current loops can radiate or conduct noise. That can be especially troublesome in a system that also contains low-level sensors.
Practical design measures include short current loops, proper ground routing, local supply decoupling, suitable gate drive, snubbers or filtering when needed, and physical separation between noisy motor wiring and sensor lines.
PWM is an actuator command, not a guarantee of output
Open-loop duty cycle produces an approximate physical effect. It does not guarantee motor RPM, airflow, temperature, light intensity, or any other final process variable. Load and supply conditions can change.
If exact motor speed is important, measure speed and close a speed loop. If humidity is the true process objective—as in the aeroponic prototype—measure humidity and let the environmental controller adjust PWM until the humidity response is satisfactory.