Author Topic: Best way to convert PWM to analog?  (Read 3034 times)

0 Members and 1 Guest are viewing this topic.

Offline stafilTopic starter

  • Regular Contributor
  • *
  • Posts: 205
  • Country: us
Best way to convert PWM to analog?
« on: March 13, 2020, 03:58:58 am »
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 output

The 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?
 

Offline Whales

  • Super Contributor
  • ***
  • Posts: 1899
  • Country: au
    • Halestrom
Re: Best way to convert PWM to analog?
« Reply #1 on: March 13, 2020, 04:38:49 am »
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).
 
The following users thanked this post: stafil

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Best way to convert PWM to analog?
« Reply #2 on: March 13, 2020, 05:01:28 am »
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.
 
The following users thanked this post: stafil

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: Best way to convert PWM to analog?
« Reply #3 on: March 13, 2020, 06:07:35 am »
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. 
 
The following users thanked this post: stafil

Offline stafilTopic starter

  • Regular Contributor
  • *
  • Posts: 205
  • Country: us
Re: Best way to convert PWM to analog?
« Reply #4 on: March 13, 2020, 07:05:15 am »
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.
 

Offline boB

  • Frequent Contributor
  • **
  • Posts: 312
  • Country: us
    • my work www
Re: Best way to convert PWM to analog?
« Reply #5 on: March 13, 2020, 07:22:14 am »

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.

K7IQ
 
The following users thanked this post: stafil

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Best way to convert PWM to analog?
« Reply #6 on: March 13, 2020, 07:28:23 am »
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.
That'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.
 
The following users thanked this post: stafil

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19528
  • Country: gb
  • 0999
Re: Best way to convert PWM to analog?
« Reply #7 on: March 13, 2020, 11:56:25 am »

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.
Yes, 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
 
The following users thanked this post: stafil

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16621
  • Country: us
  • DavidH
Re: Best way to convert PWM to analog?
« Reply #8 on: March 15, 2020, 12:04:56 am »
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.
 
The following users thanked this post: boB

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19528
  • Country: gb
  • 0999
Re: Best way to convert PWM to analog?
« Reply #9 on: March 16, 2020, 09:35:48 pm »
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
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: Best way to convert PWM to analog?
« Reply #10 on: March 17, 2020, 01:49:23 am »
I wonder how do motherboards do it. Surely RPM shouldn't stop working if I am using PWM.

Asrock 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


 

Offline thequantizer

  • Newbie
  • Posts: 4
  • Country: us
« Last Edit: January 13, 2022, 02:40:10 am by thequantizer »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf