Best way to convert PWM to analog? - Page 1
Forum section: electronics / beginners

author: stafil
author_rank: Regular Contributor
timestamp: March 13, 2020, 03:58:58 am
content: I am trying to drive a 3 pin fan using my MCU.The 3 pins of the fan are 1- Gnd, 2- Vdd, 3- Open drain RPM outputThe fan can draw up to 0.5 Amp.My initial idea was to use a Darlington transistor, something like the circuit below.The problem was however that this would mess up the RPM output.Net idea was to use a RC low pass filter and a Power Op Amp, but I think a rail-to-rail(actually don't care about the -, on the +) Op Amp rated 0.5+A would be too expensive.Any better ideas/suggestions?

author: Whales
author_rank: Super Contributor
timestamp: March 13, 2020, 04:38:49 am
content: RC low pass filter (to convert PWM to a stable controllable voltage) is a good first step.You don't need a power opamp, a single transistor in an "emitter-follower" configuration will probably do, provided you don't mind losing around 2V from the maximum voltage. See if that yields an acceptable result (the fan may be more than fast enough or you might have a different power supply handy).EDIT: I wonder how resilient the RPM output is. Can it survive the fan being directly PWM'd (from the high side, rather than from the low side as per your drawing).

author: Ian.M
author_rank: Super Contributor
timestamp: March 13, 2020, 05:01:28 am
content: PWMing the fan is likely to mess up the RPM output anyway, as the internal tacho sensor needs power to function and unless the fan is designed to be PWMed with a diode and separate reservoir capacitor to maintain power to the sensor, it wont get any during the PWM off period.You could try a high side P-MOSFET to PWM the fan supply rather than its ground, with a level shifter or even a gate driver IC to turn your logic level PWM input into what's needed to drive a MOSFET gate fast enough and hard enough for 25KHz PWM. Do't forget an anti-parallel diode across the fan in case it as a load has a significant inductive component.However if that doesn't give you a clean RPM signal, you'll probably need to go to a buck converter controlled by your MCU to provide the fan with a variable voltage continuous DC supply. The easy way to do that is to take a 3A 'LM2596' buck module off Amazon, Ebay or the usual Chinese sites and inject a current to the feedback pin of the chip to offset the output voltage its sensing. That's pretty easy to do - just RC low pass filter (with a couple of stages and a time constant a couple of orders of magnitude greater than the PWM period) your MCU's PWM output, and couple it to the feedback pin through a resistor. When the PWM is at a duty cycle that would give 1.23V out without the coupling resistor, it will have no effect on the set output voltage of the LM2596 module. Raise it and it will depress the voltage out, and lower it and it will increase it, by an amount determined by the coupling resistance (including the resistors in the low pass filter) and the resistance of the existing feedback network. You may also want to lift the LM2596i nON/OFF pin so your MCU can control that directly, rather than trying to drive the output voltage to zero to switch the fan off.N.B. Most cheap LM2596 buck converter modules have fake chips that work down around 50-60KHz rather than the 150KHz of a genuine one or better quality clone. The problem with that is the coil and capacitors are usually sized as-if it was actually going to run at 150KHz so at best a nominally 3A module will be good for 1A. In practice other cost-saving will have been made and you can only really expect 0.5A reliably, so don't try to put multiple 0.5A fans on the same module.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: March 13, 2020, 06:07:35 am
content: I'm thinking a small variable linear regulator. Control the voltage with a digital pot. You will need something to amplify your fan speed signal. It needs to stay high enough to show as H to the micro. While the fan is at 1V the output pin will still need to be able to produce a signal above 2.7V (assuming TTL voltage levels.)I played around with a fan on my scope and bench power supply. Regulating the voltage controlled the speed well, and the output signal stayed clean.

author: stafil
author_rank: Regular Contributor
timestamp: March 13, 2020, 07:05:15 am
content: Thanks folks. I tried using a PNP and driving it from the high side, but didn't help. I wonder how do motherboards do it. Surely RPM shouldn't stop working if I am using PWM. Maybe I need to do some more research on why is my RPM signal disturbed by the PWM.

author: boB
author_rank: Frequent Contributor
timestamp: March 13, 2020, 07:22:14 am
content: I'm not sure about your tachometer feedback but this basic circuit works great.FET or bipolar transistor. Lower frequency, more inductance.The R is the fan here.

author: Ian.M
author_rank: Super Contributor
timestamp: March 13, 2020, 07:28:23 am
content: Quote from: stafil on March 13, 2020, 07:05:15 amThat's what four wire fans are for - their PWM output stage is internal, so the tacho circuit can be fed with uninterrupted DC power so their RPM output remains clean.If you want to PWM a three wire fan directly, and *NEED* that RPM output for anything better than 'still spinning' status, you'll need to go to 100% duty cycle for just long enough to make the RPM measurement. If you do that infrequently enough (e.g. a few times a second) it doesn't make much difference to the fan speed.

author: Zero999
author_rank: Super Contributor
timestamp: March 13, 2020, 11:56:25 am
content: Quote from: boB on March 13, 2020, 07:22:14 amYes, an open loop buck converter will work. To make it compatible with the tachometer, it will need to be changed to high side. The polarity of the diode will need to be reversed, the NPN changed for a PNP, with level shifting. Also note the tachometer will probably not work down to 0V, so there will be a point when the voltage drops too low for it to work.Here's another thread, about smoothing PWM to a DC level.https://www.eevblog.com/forum/projects/pc-high-current-pwm-fan-controller-issues/msg1290616/#msg1290616

author: David Hess
author_rank: Super Contributor
timestamp: March 15, 2020, 12:04:56 am
content: The way to do it is what boB suggested. Use the same circuit as a buck regulator with an inductor, capacitor, and diode. The different as boB's example shows is that the diode can return to the opposite side of the fan instead of the opposite side of the power source.

author: Zero999
author_rank: Super Contributor
timestamp: March 16, 2020, 09:35:48 pm
content: Something like this. There are plenty of MOSFET driver/level shifter ICs available, the one I normally use is the TC4423, or do discrete. Obviously V1 should have good supply decoupling, which isn't shown.http://www.farnell.com/datasheets/2125133.pdf

author: JustMeHere
author_rank: Frequent Contributor
timestamp: March 17, 2020, 01:49:23 am
content: Quote from: stafil on March 13, 2020, 07:05:15 amAsrock has a "DC" mode for it's pin headers so they can control 3-pin speed. The other mode is "PWM"See:https://www.asrock.com/support/faq.asp?id=427

author: thequantizer
author_rank: Newbie
timestamp: January 13, 2022, 02:35:54 am
content: We have used RC Low Pass filters to do this. Here are some links that can help explain itLow Pass Filter Theory and CalculatorVideo simulating PWM to analog simulation using KiCadHere we used PWM and an RC Low Pass filter to create an analog audio signal to drive a speaker