Demystifying Pulse Width Modulation(PWM).
Donald Koech
Final year Electrical, Electronics Engineering student | IoT & PCB designer full time |
In my very first article,I thought to write about one of the topics that has been a little mystery to me yet so important and exciting,the Pulse Width Modulation,or popularly referred to as?PWM.
The easiest definition I could find and have used to date since I first met these three letters but with so much significance is ;A technique of obtaining analog values from digital ones,sounds easy right?
Well it is.It just comes with so much confusion but its applications sound much better than just the definition.Let's dive right into it.
PWM is a way of getting analog outputs by quickly varying the Pulse width.Pulse width is the duration of on time taken for a signal to peak and fall,and not to be confused with?frequency?which simply means number of cycles in a second(Hertz).
Another terms often used is the Duty cycle
Digital signals usually represent an on/off state or high/low or 1/0 value.Some applications are not favored by these 2 extreme states since we could use the values along the way for complete control,be it in the speed of motor or as simple as controlling the brightness of a bulb.
So basically PWM is a type of signal that is generated by tweaking duty cycles to kind of imitate analog signals ,since analog signals basically represents changes over time.
Generation of PWM
There are several methods to generate PWM signals, depending on the specific application and available resources. Here are some common techniques:
It's worth noting that the selection of a PWM generation method depends on factors such as the complexity of the application, available hardware resources, desired accuracy, and the capabilities of the microcontroller or development platform being used.
We'll cover the first and second methods for now.
1.Hardware-Based PWM Generation:
领英推荐
The message signal and the carrier waveform is fed to a modulator which generates a PAM signal. This pulse amplitude modulated signal is fed to the non-inverting terminal of the comparator.
A ramp signal generated by the sawtooth generator is fed to the inverting terminal of the comparator.
These two signals are added and compared with the reference voltage of the comparator circuit. The level of the comparator is so adjusted to have the intersection of the reference with the slope of the waveform.
Check out the signals produced by each component below,courtesy of?electronics coach
2 .Software-Based PWM Generation:
Anyone who's played around with MCU boards like Arduino have probably come across PWM pins.
With all the Hardware doing the background work,it becomes easy to just set a desired analog value between 0 and 255 (0 representing 0 volts and 255 being the highest voltage signal like 5V etc.)
Learn more about Arduino?here.
Arduino has 6 dedicated pins for PWM and can be used by the function;
analogWrite(pin, value)
Perhaps the basic application is the dimming of an LED when you need a value in between total on /off state.
I used 3 LEDs and wrote the code below which controls the brightness using pin 3,
int led=3;
int max=255;
int min=0;
int i;
void setup(){
pinMode(led,OUTPUT);
}
void loop(){
for(i=min;i<=max;i++){
analogWrite(led,i);
delay(10);
}
for(i=max;i>=min;i--){
analogWrite(led,i);
delay(10);
}}
For demo check?here;
Another typical application is the motor control,but that's for another day.
Advantages of PWM
Disadvantages of Pulse Width Modulation
That's all the basics,still not simple but this article definitely goes a long way to demystify PWM.Check my blog for related content.
--INTERN
1 年Wow amazing
Really insightful sir ??