Introduction
DAC. I teased this acronym in the previous course, but what is it? DAC stands for Digital to Analogue Converter. As the name tells you, it converts digital values to analogue ones, usually voltage, sometimes current. DAC’s usefulness should be self-explanatory, but to state the obvious: whenever you need a way to convert digital signal into an analogue value, you use a DAC. But this was just a teaser for the next course. Today we’ll be looking at pulse width modulation (PWM), which may be, as we’ll explore today, used to generate a stable voltage. If you are reading this document, I am sure you have used PWM before. It is a handy tool for dimming light sources, adjusting power of small motors, and much more. PWM works by powering the device only part of the time, which reduces the average device output power. If repetition cycle is fast enough, we perceive only the average output power. But how is it generated? When can you use it? Can it be improved?
Digital PWM
Here is how PWM is implemented in microcontrollers: they have a counter with predetermined size. On each clock cycle this counter is incremented by one. When counter overflows, it resets to zero and output is set high voltage level. Counting continues indefinitely. When counter matches a reference value, output drops to low voltage level. Varying the reference value effectively varies the output waveform.
As you can see in the picture above, varying the reference (blue) will affect pulse width (red). There are two edge cases though: when reference is zero and when reference is max. PWM cannot output 100%, because counter will always match reference value at least at max value. Inversely, it can easily output 0%, even though it is supposed to set output high when counter overflows. This is because output is set high and then immediately set low because it matches the reference. Digital PWM modulators have a finite resolution. Depending on the size of the internal counter, they can only output a predetermined amount of pulse shapes. If counter has four bits, as seen in image above, modulator will have sixteen different possible pulse widths (2^4). An eight bit counter would result in 256 possible pulse widths and so on.
Efficiency
If flickering may be a problem, why would we even bother uising PWM? PWM is great, because it lets us achieve high efficiency. Since signal is either high or low (output transistors are fully opened or closed), resistive losses are minimized. Compare that with an OpAmp’s output stage, where the difference between supply voltage and output pin are wasted on output transistors. At high load currents, power losses add up. A quick reminder, power loss is equal to the product of the voltage drop and the current.
Analog PWM
Analog PWM is generated in much the same way as a digital one. We need a rising voltage, that periodically resets (a sawtooth waveform), a reference voltage, and a way to compare them (a comparator). If reference is above “counter” voltage, output is high and vice versa.
Conclusion
And this brings us to the end. We’ve looked at PWM, how it works, its benefits, and drawbacks. We even discussed human physiology for a moment. I hope you found this course interesting and maybe even useful for one of your projects. Until next time, cheers!
Written by Luka Pogačnik
This teaching material was created by Red Pitaya & Zavod 404 in the scope of the Smart4All innovation project.