){.nav-menu .menu-item-has-children a{padding-right:20px}.nav-menu .menu-item-has-children a:after{position:absolute;right:7px;top:10}}.vce-ad-container{margin:30px auto;display:block;clear:both;width:728px;position:relative;max-width:100%}.vce-ad-below-header{margin-bottom:0}@media only screen and (max-width:1200px) and (min-width:1024px){.vce-ad-container{width:630px}.vce-ad-below-header{width:728px}}@media only screen and (max-width:1023px){.vce-ad-below-header,.vce-ad-container{width:728px}}@media (max-width:767px){.vce-ad-container{width:375px}}@media (max-width:400px){.vce-ad-container{width:300px}}@media (max-width:320px){.vce-ad-container{width:280px;max-width:100%}}:root .main-navigation ul ul{opacity:1}@media only screen and (min-width:1024px) and (max-width:1200px){.container{max-width:1000px}.vce-main-content{width:700px}.main-navigation ul ul{display:none}.top-header{overflow:hidden}.main-navigation a{padding:15px 9px 15px}.search-header-wrap a{padding:15px}.header-3-wrapper .site-branding{max-width:300px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (min-width:670px) and (max-width:1023px){.header-3-wrapper .site-branding{max-width:300px}.header-3-wrapper .nav-menu>li>a{padding:0 15px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (max-width:1023px){.container{max-width:90%}.vce-main-content{width:100%;padding:15px 0!important}.main-navigation ul ul{display:none}.vce-res-nav{float:left;position:absolute;left:0}.header-3-wrapper{height:50px!important;padding-top:0!important;text-align:center}.header-3-wrapper .site-branding{position:relative;float:none;top:0!important;left:initial!important;text-align:center;max-width:initial;padding:3px 0 7px}.site-branding{padding:4px 0 7px;display:inline-block}.site-branding img{max-width:120px;max-height:28px}.main-header .header-3-wrapper .site-title,.main-header .header-3-wrapper .site-title a.has-logo{line-height:40px!important;font-size:26px!important}.sidebar{margin:0 auto 20px;float:none!important;display:block;clear:both;padding-top:0!important;width:100%;max-width:300px}h1.entry-title{max-width:100%}.vce-responsive-nav{display:block;margin:10px 0 9px}.nav-menu,.top-header{display:none}.main-header .site-title,.main-header .site-title a{line-height:36px!important;font-size:40px!important}li>ul{margin:0}}@media only screen and (min-width:200px) and (max-width:670px){html{margin-top:0!important;overflow-x:visible}html body,button,input,textarea{font-size:14px;line-height:22px}.container{max-width:95%}.vce-main-content{padding:0 0 10px!important}.main-box,.sidebar .widget{margin-bottom:10px}.vce-wrap-right{width:100%;max-width:100%;text-align:center}.vce-single .entry-header{margin:20px 0}.vce-wrap-right{text-align:center}body h1.entry-title{font-size:24px;line-height:30px;padding:0 20px}body p{margin-bottom:20px}body h1{font-size:24px;line-height:34px;margin-bottom:10px}body h4{font-size:18px;line-height:28px;margin-bottom:10px}.sidebar .widget-title{line-height:22px}.vce-wrap-right>ul{float:none;display:inline-block;margin:10px 0 0}}#cookie-notice *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#cookie-notice .cookie-notice-container{display:block}#cookie-notice.cookie-notice-hidden .cookie-notice-container{display:none}.cookie-notice-container{padding:15px 30px;text-align:center;width:100%;z-index:2}.cn-close-icon{position:absolute;right:15px;top:50%;margin-top:-10px;width:15px;height:15px;opacity:.5;padding:10px;outline:none}.cn-close-icon:before,.cn-close-icon:after{position:absolute;content:' ';height:15px;width:2px;top:3px;background-color:#fff}.cn-close-icon:before{transform:rotate(45deg)}.cn-close-icon:after{transform:rotate(-45deg)}#cookie-notice .cn-button{margin:0 0 0 10px}.cn-button.bootstrap{font-family:-apple-system,BlinkMacSystemFont,Arial,Roboto,"Helvetica Neue",sans-serif;font-weight:400;font-size:13px;letter-spacing:.25px;line-height:20px;margin:0;text-align:center;text-transform:none;display:inline-block;touch-action:manipulation;white-space:nowrap;outline:none;box-shadow:none;text-shadow:none;border:none;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;text-decoration:none;padding:8.5px 10px;line-height:1}.cn-button.bootstrap{color:#fff;background:#20C19E}.cn-text-container{margin:0 0 6px 0}.cn-text-container,.cn-buttons-container{display:inline-block}@media all and (max-width:900px){.cookie-notice-container #cn-notice-text{display:block}.cookie-notice-container #cn-notice-buttons{display:block}#cookie-notice .cn-button{margin:0 5px 5px 5px}}@media all and (max-width:480px){.cookie-notice-container{padding:15px 25px}}

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!

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.

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%.

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:

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:

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);
}

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!

Random Scope Trace

Leave a Comment X

13 Comments

  • This is realy good project.Thank you for your share. how can İ set max output analog voltage to 6.25v. Thank you for your help.

    • Aky:

      Here, the maximum output is around 10V but you can ‘tune’ the trimpot to set 6.25V output. Or, if you want to scale down the maximum output to 6.25V (instead of the 10V) when trimpot is at its maximum sweep, try to fiddle with the code line “pwmValue = map(pwmValue, 0, 1023, 0, 255)” accordingly. You can refer this too, https://www.arduino.cc/reference/tr/language/functions/math/map/

      BTW, version 2 (v2) of this project is now under preparation, so you can see it in near future. Thanks for your query!

  • Hello, i am interested to make this, you mentioned in a comment that v2 is coming soon, how soon, because i need to build this. Also can it be powered from the 12V power supply, it would be great if it could. My best regards and thanks for the help!

    • Frissco,

      I’ll try to share the next part as quickly as possible. It is requested to periodically visit this page for relevant updates.

      If you’ve a well-regulated 12VDC power supply handy, yes you can omit the 7812 regulator and feed your 12VDC directly to the +12V rail, that means, across C4.

      Thank You!

      • Hello there again, how is your progress on V2 of this doing, i hope it will be out soon,becuase i really need it for my CNC to control a VFD speed settings with it. And also am i correct when i think that the change in output voltage is not linear on this. One question is would it be possible to get it to be linear change in voltage? Thanks in advance ! Best regards!

  • hi i did the circuit but i need the out put 200ma cureent the i set it to load my voltage freezes i dont know how to fix it please help me here
    sorry for bad english