Pulse Width Modulation (PWM) is a technique used to encode information in the form of a varying signal by changing the width of pulses in a sequence of pulses. It is commonly used in electronics to control the average power delivered to a load, such as in motor control, light dimming, or generating analog signals from digital ones.
By varying the width of the pulse, i.e., determining the amount of time the signal should stay high (on) and low (off), we can control the power delivered to the assigned GPIOs. The portion of the period where the PWM signal is high is called the duty cycle.
The duty cycle in PWM is expressed as a percentage and represents the ratio of time the signal is high relative to the total period. A higher duty cycle means that the signal is on for a larger percentage of the period, resulting in a higher average output voltage for that duration. A lower duty cycle leads to a lower average output voltage.
Some terms and formulas that can be good to know are
The PWM module enables the generation of a pulse with modulated signals on a GPIO, and implements an up or down counter with four PWM channels that drive assigned GPIOs.
For example, the PWM module on the nRF52840 can provide up to four PWM channels with individual polarity and duty cycle values that can be used independently of each other. This means that you can drive multiple entities using a PWM signal generated from this module, each having a different duty cycle and/or polarity.
There are also different configurations of PWM output: