Smooth voltage from PWM controlled PNP transistor, variable load

I'm trying to achieve a kind of dynamic low pass filter for the output of a PNP transistor. I will use PWM (currently via an NPN transistor) to drive 12V 3-wire PC fans. The fans will have one transistor each, and individually variable duty cycle, but fan load may vary from <0.1A to 0.3A. I'd like to have the design variable and dynamic for all outputs, and if manual control is necessary I'd like to have that programmable via Arduino, if feasible.

I have Arduino Unos and the almost identical 16MHz Nano type. It'll be used to control 4-8 fans, and I may hook up a TLC5940 for the PWM control of the PNP transistors, eventually. The fans have a hall sensor feedback for rotation speed, but with a switching supply voltage, this feedback is not at all reliable.

Any suggestions for how I can achieve a smooth voltage output that follows the desired duty cycle for reduced fan speed?

Do you have RPM feedback?

Edit I reread your post and saw that you stated that the fans have hall effect sensors.

what is the purpose of this aplication, Cooling a large PC.

what are the tolerances?
is the goal steady airflow?
would you be willing to add an airflow meter?
PID may be a good solution, What should the PV be, Tempature, airflow, something else?

Geogak:
Do you have RPM feedback?

Edit I reread your post and saw that you stated that the fans have hall effect sensors.

what is the purpose of this aplication, Cooling a large PC.

what are the tolerances?
is the goal steady airflow?
would you be willing to add an airflow meter?
PID may be a good solution, What should the PV be, Tempature, airflow, something else?

PID? Oh please, they are fans! Airflow is proportional to speed. Speed is equal to applied voltage. Good grief man, this ain't rocket science.

Now, back to the OP. You used so many buzz words in your description, I'm not sure what you are really trying to do. Just what is "variable and dynamic"? I fully understand variable, that is the point of PWM but what do you mean by using the word dynamic? Just being redundant?

You also said:

The fans have a hall sensor feedback for rotation speed, but with a switching supply voltage, this feedback is not at all reliable.

The reason for hall sensor feedback is so you can apply PWM and still get solid speed feedback from the fan. It is in the form of a pulse or pulses for each rotation of the shaft. So, your statement is confusing since hall sensor feedback is independent of the fans supply.

In the end, it doesn't matter if you use an NPN or PNP transistor, that only changes the logic polarity to drive it. But, given a 300ma load, I'd go with a logic level mosfet rather than trying to use a transistor since mosfets are superior to transistors for use as on/off switches. A small, simple N channel device like the IRLML0030TRPBF is fine for PWM'ing a 12 volt fan, just don't forget a diode across the fan.

Geogak:
what is the purpose of this aplication, Cooling a large PC.

what are the tolerances?
is the goal steady airflow?
would you be willing to add an airflow meter?
PID may be a good solution, What should the PV be, Tempature, airflow, something else?

The purpose is to cool medium to large size PCs either with reduced noise and/or low temperatures as the main goal.

I'd like to have individual control of each fan, and as input to their automatic control I plan to add several temperature probes.

I am not familiar with air flow meters, but I'm not against trying to incorporate them. I could possibly also make custom hall effect sensors for each fan, but that may produce unwanted noise, and I'd also prefer to not have such components visible.

avr_fred:
Now, back to the OP. You used so many buzz words in your description, I'm not sure what you are really trying to do. Just what is "variable and dynamic"? I fully understand variable, that is the point of PWM but what do you mean by using the word dynamic? Just being redundant?

I'd like to have the voltage be variable (e.g. using some PWM driver for simplicity), and the voltage smoothing to accommodate for a large range of loads dynamically. E.g. with a 50% duty cycle, to get close enough to a smooth 6V to allow for a reliable RPM feedback signal. I don't know if I can achieve this with a simple low pass filter.

avr_fred:
The reason for hall sensor feedback is so you can apply PWM and still get solid speed feedback from the fan. It is in the form of a pulse or pulses for each rotation of the shaft. So, your statement is confusing since hall sensor feedback is independent of the fans supply.

Normally, 3 and 4 wire computer fans pulse once on the sense wire per half revolution of the blades. The constant switching on and off of the 12V power when driven by a PWM controlled transistor or MOSFET is not only switching the motor, but also affects the hall effect sensor. For my 3 wire fans this appears to result in a lot of jitter on the sense wire. When I have my Arduino set to register interrupts on a rising edge, I get several thousands of triggers per second. And some fans, at some "sweet spot" duty cycle below 100%, seem to mess up the Arduino's internal time keeping (millis() and delay() are affected), but that's another issue.

Driving my 4 wire fans, which can accept a PWM signal directly on the fourth blue wire, using a PWM controlled transistor or MOSFET seem to give me valid RPM measurements even below 100% duty cycle. I assume these fans have some more advanced design and that their hall sensor is somewhat isolated.

I have some Noctua 3 wire fans which do not seem to produce any useful RPM signal data at much less than 12V, even if there is no fluctuations in the supply voltage. At least they do not constantly send a signal full of jitter when the voltage is held constant.

avr_fred:
In the end, it doesn't matter if you use an NPN or PNP transistor, that only changes the logic polarity to drive it. But, given a 300ma load, I'd go with a logic level mosfet rather than trying to use a transistor since mosfets are superior to transistors for use as on/off switches. A small, simple N channel device like the IRLML0030TRPBF is fine for PWM'ing a 12 volt fan, just don't forget a diode across the fan.

I'm open to all suggestions. I have access to multiple transistors (NPN and PNP), and a couple of NPN MOSFETs. I do not yet have any PNP MOSFETs at home. The PNP transistor I chose for my latest test is low voltage (20V) and most importantly high current (700 mA). It works just as well as the NPN MOSFET I initially used. Both circuits cause a lot of jitter from the hall effect sensor, when driven at anything less than a 100% duty cycle. The advantage I saw with the PNP transistor is when paired with something like the constant current PWM driver that the TLC5940 is.

Perhaps what I'm after is a simplified buck converter, if there is such a thing.

When you mention noise, do you mean noise from the fan?
Is the low pass filter meant to reduce the fan motor noise?
Are your fans compatible with higher frequency PWM, like 25kHz?

If so, this could greatly reduce the motor noise without filtering the PWM. But if for some reason filtering is necessary, filtering 25kHz is much easier than filtering 500Hz.

Might want to look into using a Mega as it has four 16-bit timers available and two 8-bit ones. Since each timer has 2 outputs, this should work fine controlling 8 fans with high frequency PWM.

dlloyd:
When you mention noise, do you mean noise from the fan?

Yes.

dlloyd:
Is the low pass filter meant to reduce the fan motor noise?

I believe I need to smooth out the voltage curve, as while switching between fully on (+12V) and off (0V) is sufficient to get a decent fan curve, it is not giving me the desired sense wire output for its hall sensor RPM measurements.

dlloyd:
Are your fans compatible with higher frequency PWM, like 25kHz?

The 4-wire fans are compatible with ~25kHz PWM directly, on the fourth, blue, wire. I don't need any transistor for these, and can send the PWM signal directly to the fan, together with a clean 12V feed.

The other fans, with the same PWM signal driving a transistor or MOSFET, there's also no problem with the fan drive itself. Only the hall sensor output.

dlloyd:
If so, this could greatly reduce the motor noise without filtering the PWM. But if for some reason filtering is necessary, filtering 25kHz is much easier than filtering 500Hz.

My current proof-of-concept sketch is using a ~31 kHz PWM output from pin 9 (timer1 with no prescaler). At default ~500 Hz PWM, the 4-wire fans make some audible noise when fed less than 100% duty cycle on the PWM control wire, which is why I set the timer1 divisor to 1. At ~31 kHz, I haven't noticed any motor noise related to the variable voltage at lower duty cycles.

dlloyd:
Might want to look into using a Mega as it has four 16-bit timers available and two 8-bit ones. Since each timer has 2 outputs, this should work fine controlling 8 fans with high frequency PWM.

I have hopes I will be able to run a TLC5940 at a high enough resolution (4 or 5 bit PWM resolution is sufficient for this application) at around 25 kHz, which will give me 16 independent PWM outputs for both 3 wire (non-PWM) and 4 wire (direct PWM) fans.

It's for the non-PWM 3 wire fans where I'd need a smoother voltage curve for the RPM measurement.

Would an inductor and a capacitor be all that I need, for a 25-30 kHz switching transistor/MOSFET, either high-side or low-side drive? I don't think I need a particularly quick transient response, and the duty cycle won't need to change very quickly. I don't know enough about this area of electrical engineering and circuit design to know if this is a bad idea from the start.

I'm also open to sourcing a higher frequency PWM driver if that would make this even easier, and reduces other kinds of complexities. These Arduinos can only be pushed so far. If I can drive a transistor or MOSFET at a much higher frequency, perhaps I won't have this issue with their internal hall sensors.

A 3 wire fan suggests that the hall sensor is connected either to the low or high fan voltage. If it connects to the low voltage, you should use a high side PWM switch, else a low side switch, to keep the hall sensor at a fixed voltage. If the hall sensor is open collector, a pullup or pulldown resistor is required.

The PWM frequency should be above the audible range, 31kHz should be fine (what about dogs?)

DrDiettrich:
A 3 wire fan suggests that the hall sensor is connected either to the low or high fan voltage. If it connects to the low voltage, you should use a high side PWM switch, else a low side switch, to keep the hall sensor at a fixed voltage. If the hall sensor is open collector, a pullup or pulldown resistor is required.

The PWM frequency should be above the audible range, 31kHz should be fine (what about dogs?)

Unfortunately I've not had any luck with neither high side nor low side MOSFET or transistor drive of 3 wire fans and simultaneous hall sensor functionality. I've also tried to have the incoming voltage switching between +12V and +4.3V (hooked up to +5V via a 1N4001 diode), but the hall sensor still does not work.

The specification I've found is that the hall sensor is open collector, and you pull the wire up to either 5V or 12V. I pull it up to 5V for direct use with Arduino. This works well at a stable voltage, i.e. not PWM-controlled or at 100% duty cycle.

For 4 wire fans, the spec calls for a PWM frequency of around 25kHz on the fourth wire. My 4 wire fans have their hall sensor isolated internally, and so keeps functioning even when I control its voltage with a MOSFET or transistor.

First of all forget about "smoothing" a PWM signal. The driver transistors must only fully turn on and off, any voltage in between tends to kill them. Smoothing of the supply current is done by the inductance of the motors.

Please provide a complete circuit diagram, how you attach the hall sensor, power supply and a fan with a high side driver. I suspect wrong cabling.

Many components are built into these types of fans, so I have no control over how the hall sensor is hooked up internally. I can supply 12V to the whole package, or not at all.

I found a very detailed description of the inner workings of these types of fans, and the author is experiencing the same problems I face. Please look at his pictures where he describes how the output of the tachometer/hall sensor matches the incoming PWM, which at less than 100% duty cycle will make it difficult to get a clear reading.

I don't have an oscilloscope to measure the output from the sense wire. I have many fans which may be have slightly differently so a single catch-all solution using a capacitor and an inverter may not work reliably. He also mentions he had some issues with one fan stalling, using this approach, although this could be worked around using code.

He also has a few other workarounds. I prefer some variation of this "pulse stretching method", and I may end up using it. This will reduce the wiring complexity.

If you (or somebody else) claim that many components are built into the fan, what's the purpose of these components? How can you be sure that the third wire is connected to a hall sensor? Somebody else recently presented a fan with a PWM input on the third wire, and this were an example where many components are built into the fan, for the H-bridge.

If you want to proceed, you can try one of the solutions presented in the links, or get a scope for more experiments, or get fans with a properly separated hall sensor.

If this is what the RPM feedback signal looks like for all of your fans

Then it should be simple to clean up with a diode, resistor and capacitor

Even if the signal isn't perfectly cleaned, it will prevent flooding an interrupt pin with multiple false triggers. Then the code could detect the first falling edge after a stable HIGH interval. (20-30kHz PWM assumed)

DrDiettrich:
If you (or somebody else) claim that many components are built into the fan, what's the purpose of these components? How can you be sure that the third wire is connected to a hall sensor? Somebody else recently presented a fan with a PWM input on the third wire, and this were an example where many components are built into the fan, for the H-bridge.

If you want to proceed, you can try one of the solutions presented in the links, or get a scope for more experiments, or get fans with a properly separated hall sensor.

First of all let me say that I appreciate all the help and ideas provided here. The pcbheaven postings I found may be good reference for anyone else who wants to achieve something similar with these types of fans.

The fans I have are all generic computer fans. They are built to a fairly simple specification, and are made to be connected to either 3-pin or 4-pin headers on a motherboard. I have found a specification for the 4-wire fans, but not for the 3-wire fans. It should be generally applicable to all PC fans like these with both 3 or 4 wires, as I assume the 4-wire fans build upon the 3 wire fans for compatibility and to not destroy any motherboards. The 3-wire fans have a first wire for ground, a second wire for up to +12V input, and a third wire for sense (the hall sensor). The 4-wire fans add a fourth wire for direct PWM control. They are ubiquitous. I would hope that they mostly follow the same general standard, although there may of course be some exceptions. All my fans seem to behave similar, if not identical, except for their fan curves. Unfortunately I cannot verify their sense wire output without a scope, and that is making this a bit trickier than I would have hoped.

Intel's 4-wire fan specification says that the hall sensor will pulse the sense wire twice per revolution, and the motherboard will provide the pull-up to +12V. It's an open-drain or open-collector port.

http://www.formfactors.org/developer/specs/rev1_2_public.pdf

dlloyd:
If this is what the RPM feedback signal looks like for all of your fans

Then it should be simple to clean up with a diode, resistor and capacitor

Even if the signal isn't perfectly cleaned, it will prevent flooding an interrupt pin with multiple false triggers. Then the code could detect the first falling edge after a stable HIGH interval. (20-30kHz PWM assumed)

I believe I've tried connecting the sense wire like this, instead of simply one pull-up and one series resistor, before I found the pcbheaven page and saw his scope output. I did not have any filtering in my code at that time. I may give this another try.

I'm also thinking that maybe some fans have components which prefer to have the sense wire be pulled up to 12V, so I could hook it up to that and introduce a voltage divider between the sense point and my Arduino to bring it down to around +5V.

I'll give both options a shot.

Could have the "RPM Feedback" pulled to 12V without affecting the filter, providing the signal can still reach near 0V.

I tried the voltage divider using large resistors (150k and 100k) but that was not successful.

Testing with high side switching (PNP transistor) shows very good results using your original proposed circuit, @dlloyd.

Using low side switching (NPN MOSFET) it also works well, except for at very low duty cycle.

I managed to get tachometer sensing (ISR called on falling edge) in the low side switching circuit to work better at low duty cycles after removing the external pull-up resistor, and instead relying only on the Arduino's internal pull-up resistor. I suspect the low duty cycle prevented a fast and reliable drain of the capacitor charge, with the small 2.2k Ohm resistor pulling it up to +5V. It currently works without any filtering.

I shouldn't risk damaging my Arduino by relying on the internal pull-up resistor only? Perhaps the downside is a greater risk for interference?

dlloyd:
Could have the "RPM Feedback" pulled to 12V without affecting the filter, providing the signal can still reach near 0V.

Pulled to 12V with the diode between it and the 5V side?

I tried this, with a 4.7k Ohm resistor between +12V and the "RPM Feedback" side. Still no external pull-up resistor to the +5V side with my current design. It works great!

Four different fans give me useful RPM feedback during my tests with as low as 10% duty cycle (or as low as they will go before stalling, if they cannot handle the low duty cycle).