PWM is an output digital signal that is commonly used to apply a proportional control signal to an external device using a single digital output pin.
PWM is a square wave (no intermediate values, only 0 and 1) that oscillates according to a given frequency and duty cycle. It encodes the information in the length of the pulse, hence its name. A Pulse Width Modulation signal has two components:
- Frequency (expressed in Hz), which describes how often the output pulse repeats
- Duty cycle (expressed as a percentage), which describes the amount of time the pulse is on
For example, a PWM signal set to 50% duty is active for half of each cycle:
You can adjust the duty cycle to increase or decrease the amount of time the signal is on, which is reflected in the average value of it (the analog equivalent). The following diagram shows how the signal looks like with 0%, 25%, and...