Electronic Circuits

PWM to Voltage Module (v1)

Late month I’d got an order from my neighboring client to build a pulse width modulation to dc voltage converter module that’s compatible with common microcontrollers and PLCs. Since it’s a fussy time for me I ordered a readymade module, the so called “PWM to Voltage Module”, from Amazon (see the pic) and handed over to him. Later I discovered that it’s a mere piece of electronics trading at sky-high prices. So finally I plotted the (minimal) design of a new module for the time to come and succeeded with great results in the end. A happy outcome!

PWM to Voltage Module

Brief Overview

Since the pwm to voltage converter converts inputted PWM digital signals into 0 to 10V analog voltage it can be used as the switching interface for PLC or and other microcontroller based controller/driver boards. Here, the output voltage can be regulated by varying the duty cycle of the pulse width modulation. On paper, pulse width modulation (PWM) is a technique of encoding a voltage onto a fixed frequency carrier wave. In PWM, instead of varying the modulation frequency with voltage, output is merely switched on and off at a fixed frequency so that percentage of the on-time is proportionate to the signal voltage. With the help of any microcontroller that has PWM, it’s easy to output a PWM signal using the “analogWrite” function in Arduino (AVR microcontroller) for example. However this will output only a PWM signal not actual voltage. The little circuitry given here can quickly and easily convert the PWM output from a microcontroller into a voltage corresponding to the percentage of the PWM. Yes, now you will have a simple digital to analog converter (DAC) for the common microcontroller without on-chip digital to analog converter.

PWM to Voltage Module-PWM from uC

Pulse Width Modulation output from a microcontroller

Design Description

Look below for the system diagram of the proposed pwm to voltage converter. As stated, the system converts 0-5V PWM signal input into 0-10V analog output. The entire system can be powered from any 15-24V (>500mA) dc power supply, and there’s an onboard auxiliary 5V regulated dc output for running external peripherals. The recommended (default) input pulse width modulation frequency is 500Hz +/- 2%.

PWM to Voltage-System Diagram

System Diagram

PWM is in fact a technique used to generate pseudo-analog signals. As it’s not truly analog, a low-pass filter (LPF) is required to merely smooth the signal into the ‘average’ output voltage of the PWM. In addition to the LPF, an Op-Amp with a gain of x2 is merged to raise the output voltage in 0-10V scale. The (optional) second Op-Amp, a unity gain (x1) one, is added up as an output buffer. Before we go any further we need to see the whole schematic. Sometimes it may become necessary to improve the design by tweaking the RC low-pass filter and gain setting components in the op-amp circuit. Okay, let me render the well-annotated factual circuit diagram:

PWM to Voltage Module - Circuit Diagram

Circuit Diagram

As we can see in the schematic, now we have everything we need to adjust the output voltage in tune with the input signal. As I mentioned, the LPF (R1 &C7) plays an important role here, and while this single-pole filter is very simple, opting appropriate values for the RC components comprehend some design decisions – that is to say,  how fast does the filter need to respond and how much ripple can we tolerate (see addendum)? With 5.1K for R1 and 10uF C7, the resultant time constant is 51mS (fc = 3.12 Hz). Transient analysis/step response graph (fPWM=500 Hz) of the LPF used here is shown below:

PWM to Voltage module-LPF Step Response

LPF Step Response

Curious readers may be wondering how I calculated the above RC values. In order to pass only the dc component of the pulse width modulated waveform, a low-pass filter with a cutoff frequency much lower than the fundamental frequency of the pulse width modulation pulse should be required. I did it on an empirical basis (an acceptable trade-off to cut out unnecessary complexity and cost) because it worked like a charm. The gracious thing about the math is, counting on your measures, there are often multiple practical RC values for the low-pass filter!

Quick Tryout

Arduino (Uno) has total 6 pins that can be configured for PWM output. The PWM signal on pin D9 (D10 as well) provides an output frequency of 490.196 Hz, so we can take it to test our prototype. Just copy-paste-upload the given test sketch, connect a multi-turn 10K trimpot at A0 (+5V-A0-GND), and feed output from D9 to the input of the pwm to voltage converter module. And then vary the trimpot to ensure that the output shifts successively in 0-10V scale. Righto?

int pwmValue = 0;
int pwmOut = 9; //D9 as PWM O/P
int trimPin = A0; //A0 as Trimpot I/P

void setup() {
pinMode(pwmOut, OUTPUT); //Set D9 as O/P
}

void loop()
{
pwmValue = analogRead(trimPin); //Read A0 
pwmValue = map(pwmValue, 0, 1023, 0, 255);
analogWrite(pwmOut, pwmValue);
}
PWM to Voltage Module- Quick Experiment

Quick experiment – from author’s lab

Addendum

A word about ripples – in my quick experiment the LPF consists of a 5.1KΩ resistor and a 10uF capacitor. With 490Hz default PWM of Arduino, this kicks in about 31mV of ripple (0.00624×5) at the input of the op-amp converter. If this is too much for a distinctive application, it would be good to increase the pulse width modulation frequency and/or try a higher order low-pass filter. A bit hard to handle indeed!

PWM to Voltage Module-Random Scope Trace

Random Scope Trace

Leave a Comment