Convert pwm to voltage.

Irving

Joined Jan 30, 2016
3,843
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
21,159
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
9,668
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?
What load did you connect?
 

ronsimpson

Joined Oct 7, 2019
2,988
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.
1653933288407.png
 

BobTPH

Joined Jun 5, 2013
8,813
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
 

Ian0

Joined Aug 7, 2020
9,668
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
3,843
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:

1653939172207.png
 

crutschow

Joined Mar 14, 2008
34,283
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
 

crutschow

Joined Mar 14, 2008
34,283
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. :rolleyes:

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.

1653966924011.png
 

Papabravo

Joined Feb 24, 2006
21,159
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.

1653977537521.png

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

Ian0

Joined Aug 7, 2020
9,668
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.
 

Irving

Joined Jan 30, 2016
3,843
@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.

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

1653995053495.png
 
Top