A pulse signal is defined by its amplitude and pulse width. A periodic pulse train has a frequency, or pulse-repetition rate, and a duty cycle—the ratio of pulse width to repetition period, varying between 0 and 100%. PWM modulates the duty cycle and keeps the period fixed. Microcontrollers, which operate in the digital domain, can generate a PWM signal. Although an analog signal is continuous in both time and amplitude, a digital signal is discrete in time—that is, it is sampled at a certain rate—and quantized in amplitude using a finite number of bits. The output of a microcontroller is typically either digital or PWM. The PWM signal typically ranges from 0 to 5V; thus, you can use it to turn an electronic power switch, a transistor, on and off and to control the amount of power a load receives.
What should the frequency of the PWM signal be? First, consider the case in which you are using the PWM signal as a DAC. Many microcontroller applications need analog output but do not require high-resolution DACs. In a typical PWM signal, the frequency is constant, but the pulse width, or duty cycle, is a variable, directly proportional to the amplitude of the original unmodulated signal. The bandwidth of the lowpass filter should equal the bandwidth of the unmodulated signal. Choose the PWM frequency to give an acceptable ripple magnitude in the analog signal. For example, if you use an RC lowpass filter, you derive the amplitude attenuation using the following equation:
Many devices inherently average an on/off signal to control their operation, based on the duty cycle. Examples include LEDs that humans and inductive loads view, such as motors and solenoids. For an inductive load, such as an LR circuit, you can derive the PWM voltage frequency so that the current waveform is within a certain percentage of the analog step response. A fundamental analysis of an LR circuit calculates the frequency according to the following equation:
A shroud of mystery often envelops devices and concepts, which can often lead to avoidance or misuse. Focusing on the fundamentals removes that mystery.