# Convert pwm to voltage.

#### MMM**MMM

Joined May 30, 2022
3
.

Last edited:

#### Irving

Joined Jan 30, 2016
2,769
This is a common requirement, yet one that many find hard to make work. Show us the schematic of your current solution attempt.

#### Papabravo

Joined Feb 24, 2006
18,786
I am trying to convert arduino's pwm output (0-255) to constant dc (0-12) based on the value of pwm at this moment (i.e. it can be varied later on). Is there an easy direct way to do this?
Using a LPF, and an Op-Amp could achieve the requirement voltage, but when connecting any device even a resistor of 1k, or 100 the voltage drop to below 5v!
In order to use PWM to make a constant voltage of 0-12V you need to start with a voltage source that can provide at least 12 volts. The Arduino's power supply is 5V or maybe 3.3 volts. Those would be the maximum voltages you can achieve with PWM.

#### Ian0

Joined Aug 7, 2020
5,504

#### Ian0

Joined Aug 7, 2020
5,504
I don't know the difference between one RC filter and then Op-Amp, but I tried the second one (RC + Op-Amp) and it works, measured the voltage difference between the output of Op-Amp and ground, it was 12v as required, but when connecting any device across these terminals it does not work and even the 12v drops to 3 volt (could be higher or lower depending on the connected device but in all cases it was less than 5)
What type is the op-amp?

#### Ian0

Joined Aug 7, 2020
5,504
Does load mean the resistance value between-ve input (pin 2) of the Op-Amp and output of Op-Amp?
No - the resistance between op-amp output and ground.

#### ronsimpson

Joined Oct 7, 2019
2,161
RC values from post #5.
C2 is optional. Could make R1C1 out if two resistor and two capacitors to improve the ripple.
I use R-R input and output amplifiers. Make certain your amplifier will work the input voltage down at 0V.
R1C1 reduces the ripple. (also C2)
Adjust R2 for a gain of what you need. 5V to 12V or 3.3V to 12V. Now it is set for a gain of 2.

#### BobTPH

Joined Jun 5, 2013
5,227
An opamp can typically source or sink only about 20mA of current. If you need more current than that, you will need a current amplifier following the op amp. A simple voltage follower might work as long as the feedback is taken from the output of the voltage follower rather than directly from the opamp.

Bob

#### BobTPH

Joined Jun 5, 2013
5,227
Low resistance, like DC computer fan, it has a very low resistance, I guess in ohms, not even in kohms
You are better off to the run the fam from the PWM signal rather than convert it to a voltage, if that is your goal.

Bob

#### Ian0

Joined Aug 7, 2020
5,504
You are better off to the run the fam from the PWM signal rather than convert it to a voltage, if that is your goal.

Bob
I'm not too sure about that. If it were simply a brushed DC motor than I would agree. Most computer fans have brushless motors and electronic drivers, which might not appreciate PWM. I would use PWM followed by an LC filter.

#### Irving

Joined Jan 30, 2016
2,769
How many wires to the fan? just red & black? Do you have a model or part number for fan, or post a picture showing any markings.

The problem, as stated above, is that the fan requires several 100mA and an opamp can source maybe 20mA. You need an opamp and a suitable NPN transistor, which depends on your fan rating. Something like:

#### crutschow

Joined Mar 14, 2008
30,100
Add an emitter follower, as Irving shows in post #20, to the circuit from ronsimpson in post #11.
The feedback goes from C2R2 to the transistor emitter.
You can use a TIP31 (with a heat-sink depending upon the fan current) or similar for the transistor

#### BobTPH

Joined Jun 5, 2013
5,227
What do you not understand in my post #14?

Bob

#### crutschow

Joined Mar 14, 2008
30,100
you are not giving a clear schematic from the input to output including all values and simulation
Sorry, I didn't realize you needed the whole design spoon-fed.
But you could have asked for that, instead of being rude, since you are getting free advice from us.

Below is the LTspice simulation with a 500Hz PWM going from 0% to 100% duty-cycle:
To get near 12V out with a 12V supply, requires a rail-rail op amp such as the LMC6484.

#### Papabravo

Joined Feb 24, 2006
18,786
The result is interesting, but the LTC6992-1 may be an unfamiliar part to many. I was curious about a number of other aspects of the circuit, so I made a copy and replaced the LTC6992-1 with a simple PWM generator using some ideal parts. These are a constant voltage reference, a sawtooth waveform generator, and an ideal comparator. I added a number of additional waveforms including the power being dissipated in the load resistor and the TIP31C. I've used the TIP31C before and it is a beast.

Not as efficient as a buck converter, but perhaps a bit easier to understand.

#### Ian0

Joined Aug 7, 2020
5,504
Low resistance, like DC computer fan, it has a very low resistance, I guess in ohms, not even in kohms
A DC computer fan is far beyond the capabilities of an op-amp

#### Ian0

Joined Aug 7, 2020
5,504
Still same issue, I have to amplify it, because the amplitude of PWM is 5v
Indeed so, but the "amplifier" is just a buffer or MOSFET driver such as MCP1402, which needs no external components.

#### Ian0

Joined Aug 7, 2020
5,504
But the other two designs of Papabravo and crutschow uses an Op-Amp, so can how we confirm that the Op-Amp used will not be so useful with fans?
look in the op-amp datasheet for the line stating the maximum output current. (Usually about 25mA), compare that with the current required by a computer fan (probably about 250mA)
@Papabravo and @crutschow buffered the output of their op-amps with a power transistor.

#### Ian0

Joined Aug 7, 2020
5,504
Sorry, didn't understand your comment as I don't know much about MOSFETs
no need for an op-amp, and much more efficient.

#### Irving

Joined Jan 30, 2016
2,769
@Ian0 - not seen that specific device before, but its bigger brother TC4429 does up to 6A in an 8-pin DIP and at £2.15 (1-off, RS Comp.) its no more expensive than an opamp & a TIPxx. Application note AN798 shows a simple motor speed controller that uses the motor back-emf as a speed feedback.

This could be adapted with an opamp instead of the speed pot, something like... (not tested)