How-to use PWM to Generate Analog (or Analogue) Voltage in Digital Circuits

Summary of How-to use PWM to Generate Analog (or Analogue) Voltage in Digital Circuits


This article discusses generating analog voltage in digital circuits using Pulse Width Modulation (PWM) to reduce costs and component count compared to dedicated DACs or R2R methods. It explains that a low-pass filter converts a PWM signal's duty cycle into a proportional continuous voltage.

Parts used in the PWM Analog Voltage Project:

  • Microcontroller
  • PWM pin
  • Low pass filter
  • Two external components

Many times, designers are faced with the need of generating analogue or analog voltage levels in purely digital circuits. Although the market provides today a very broad range of dedicated digital-to-analogue converters, putting such a device in the schematic has a negative impact on the overall cost of the system.

1. Introduction

In the first part of this article (Generating Analog Voltage with Digital Circuit (I) ), we have detailed what is known as the R2R method for obtaining an analogue voltage. The advantage of this method is that it is very much similar to use a real off-the-shelf DAC integrated circuit; the digital values you would need to generate with the code running on the microcontroller are the same in both cases.
The main drawbacks of this method, however, is the high number of pins required on the microcontroller (directly proportional to the resolution you need) and the relatively high number of external components needed (an additional pair of resistors for each additional bit of resolution).
In order to address these problems, another solution is available: the PWM solution. This allows us to obtain analogue voltage using just one pin of the microcontroller, and as little as two external components (figure 1).

http://dev.emcelettronica.com/how-to-use-pwm-to-generate-analog-or-analogue-voltage-in-digital-circuits

The theory behind the solution is that if you have low pass filter good enough and a pulse train signal, you will be able to obtain at the output of the filter the medium value of this particular signal; the medium value of a pulse train signal is always proportional to the duty cycle of the pulse train. If your duty cycle is 0%, then your PWM signal is actually always 0, and the signal at the output of the filter will obviously be also 0. If the duty cycle is 100%, then your PWM signal is actually a continuous voltage signal, equal to VCC, which even filtered, will yield the same continuous value: VCC.
In case the duty cycle is varied between these two limits (0% and 100%) the low-pass filter (provided it is correctly dimensioned) will basically cut the variations in the signal, leaving only the continuous component of the signal (its medium value) pass through. The diagrams in the figure 2 and 3 illustrate the case in which the duty cycle is 50% and 10% respectively. The green represents the PWM signal, while the red represents the continuous (analogue) signal obtained at the output of the filter.

For more detail:  How-to use PWM to Generate Analog (or Analogue) Voltage in Digital Circuits

Quick Solutions to Questions related to PWM Analog Voltage Project:

  • How does PWM generate analog voltage?
    A low pass filter processes a pulse train signal to output its medium value, which is proportional to the duty cycle.
  • Can you obtain analog voltage with just one microcontroller pin?
    Yes, the PWM solution allows obtaining analog voltage using only one pin of the microcontroller.
  • What happens if the duty cycle is 0%?
    If the duty cycle is 0%, the PWM signal is always 0, resulting in an output of 0 from the filter.
  • What happens if the duty cycle is 100%?
    If the duty cycle is 100%, the signal becomes a continuous voltage equal to VCC even after filtering.
  • Does the duty cycle affect the output voltage?
    Yes, varying the duty cycle between 0% and 100% changes the continuous component passing through the filter.
  • What is required for the low pass filter?
    The filter must be correctly dimensioned to cut variations and leave only the continuous component of the signal.
  • Why use PWM instead of R2R method?
    PWM requires fewer pins on the microcontroller and significantly fewer external components than the R2R method.
  • What represents the continuous signal in the diagrams?
    In the diagrams, the red line represents the continuous analog signal obtained at the output of the filter.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter