Arduino Forum

Using Arduino => General Electronics => Topic started by: Dylfish on Dec 16, 2012, 04:19 pm

Title: Fan Control Theory
Post by: Dylfish on Dec 16, 2012, 04:19 pm
Hey Guys,

Im looking to control 3 fans (12v PC Case, Arctic f12 PWM) and i was wondering if my logic is correct.

Since the fans are connected to +12v could I use a transistor as a switch connected to pin 3 set up so when the PWM duty cycle goes high it connect the grounds of the fans and allows me to throttle them that way? The 12v will eventually be from an external Molex connector.

Would there be any downsides if done correctly like fan wear or any dangers im unaware of?

Cheers
Title: Re: Fan Control Theory
Post by: dc42 on Dec 16, 2012, 04:45 pm
That should be fine, I've controlled a PWM fan like that, I think it was an Arctic F12 pwm too. Bear in mind that the Intel PWM spec only guarantees that fans will run from 30% pwm to maximum. Also, if you drive the fan PWM input from an NPN transistor or N-channel mosfet (the easiest way), then the PWM works in inverse mode, i.e. the more the Arduino output pin is high, the slower the fan speed.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 16, 2012, 11:48 pm
cool thanks,

How does the inverse part work? Would a npn work different to a pnp in regards to how it switches? I'll have to look into mosfets as i never have used them.
Title: Re: Fan Control Theory
Post by: krupski on Dec 17, 2012, 12:01 am

That should be fine, I've controlled a PWM fan like that, I think it was an Arctic F12 pwm too. Bear in mind that the Intel PWM spec only guarantees that fans will run from 30% pwm to maximum. Also, if you drive the fan PWM input from an NPN transistor or N-channel mosfet (the easiest way), then the PWM works in inverse mode, i.e. the more the Arduino output pin is high, the slower the fan speed.


I've done that (PWM control a PC muffin fan). You need to be sure that the PWM frequency is high enough not to alias with the switching speed of the fan at any RPM, otherwise the fan will tend to "jump" in speed at the alias point, then the loop will try to correct it and the fan will hunt "zoom..... slow....zoom...slow....".

Or, use a parallel capacitor to smooth out the PWM into a reasonably clean DC level so that the fan can't alias with the PWM frequency.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 17, 2012, 10:04 am
Sorry what do you mean by alias with the fan?
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 10:19 am

I've done that (PWM control a PC muffin fan). You need to be sure that the PWM frequency is high enough not to alias with the switching speed of the fan at any RPM, otherwise the fan will tend to "jump" in speed at the alias point, then the loop will try to correct it and the fan will hunt "zoom..... slow....zoom...slow....".

Or, use a parallel capacitor to smooth out the PWM into a reasonably clean DC level so that the fan can't alias with the PWM frequency.


We're talking about PC fans with a separate PWM input, so the above doesn't apply. However, the Intel PWM fan specification calls for the PWM to be at 25kHz, +- 2kHz AFAIR.
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 10:25 am

How does the inverse part work? Would a npn work different to a pnp in regards to how it switches? I'll have to look into mosfets as i never have used them.


There isn't a good way to use a PNP transistor to interface the fan because it's designed to be driven from an active low open-collector/open-drain output.

You can program the counter-timer to get inverse PWM, it's one of the options in the control register.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 17, 2012, 11:30 am
I have been looking at this and im thinking it might be the way to go.

http://bildr.org/2012/03/rfp30n06le-arduino/

Hopefully i can run the 3 fans this way PWM controlled fan or not. I dont have much experience with mosfets but this might the time to start.
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 11:40 am
Personally, I would stick with fans that are designed for PWM use, and use a 2N7000 small signal mosfet to drive the PWM pin.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 17, 2012, 02:48 pm
Yeah, When ive tried with direct PWM i cant get it to scale down to nearly nothing. Im thinking ill use the PWM signal to open and close a switching MOSFET as if I were disconnecting the fans hand by hand. Would this damage the fan?
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 02:57 pm
I still don't understand why you are talking about PWMing the power to the fans, when the fans you are talking about have a pwm control input. Either way, you won't get the fan speed to go down to nearly nothing. The Intel spec for PC fans with PWM input requires them to go down to 30% or less.

btw if you PWM the power to the fans, then the tacho output from the fan won't work. If you use the pwm input, then it will work as normal.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 17, 2012, 03:09 pm
im only saying that because the PWM control pin with analogwrite(3, 0) would only decrease the speed by 5% (barely noticeable).

Then again i don't know if its anything I'm doing incorrectly. I have the gnd from the arduino to my breadboard and then 12v into the breadboard terminal strip, so the grounds are common. The fan is connected to the 12v and gnd on the breadboard and the blue PWM wire is connected directly to pin 3.

If i wont need to PWM the power what is the use of the mosfet? Sorry for the stupid question and thank you for all your help.
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 04:03 pm
PC fan PWM inputs are supposed to be driven from an open-collector or open-drain output, at a frequency of 25kHz. I posted suitable code in my response to your question in the Microcontrollers section. That code has been tested on a PWM fan - an Arctic F12 PWM afair.

The best way to drive the fan PWM input is one of the following:

1. Use a small signal npn transistor such as BC337 or 2N3904. Connect collector to fan PWM input, emitter to ground, and base to Arduino PWM output pin through a 10K resistor.

2. Use a small signal mosfet such as 2N7000. Connect drain to fan PWM input, source to ground, and gate to Arduino PWM output pin (no resistor needed when driving a small signal mosfet from an Arduino pin).
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 04:08 pm
PS - just noticed you are trying to use pin 3. You can't get accurate 25KHz PWM from pin 3 because that pin is controlled from an 8-bit timer. If you use analogWrite then the PWM frequency you get is about 490Hz. The code I posted in the other thread generates 25KHz PWM on pin 10 (on a Uno).
Title: Re: Fan Control Theory
Post by: krupski on Dec 17, 2012, 04:09 pm


I've done that (PWM control a PC muffin fan). You need to be sure that the PWM frequency is high enough not to alias with the switching speed of the fan at any RPM, otherwise the fan will tend to "jump" in speed at the alias point, then the loop will try to correct it and the fan will hunt "zoom..... slow....zoom...slow....".

Or, use a parallel capacitor to smooth out the PWM into a reasonably clean DC level so that the fan can't alias with the PWM frequency.


We're talking about PC fans with a separate PWM input, so the above doesn't apply. However, the Intel PWM fan specification calls for the PWM to be at 25kHz, +- 2kHz AFAIR.


Actually, I was talking about a plain old 3 wire fan (power, ground and tach output).

When the fan is spinning, the hall sensor switches the two phases back and forth (acting like the commutator on a DC brush motor). Obviously, this occurs at a rate (frequency) proportional to the fan RPM. If the PWM frequency of the driver is near the switching rate of the fan motor, strange things will happen. I know this because I've had the problem and figured out what it was.

I was NOT talking about a 4 wire "Intel style" PWM speed controlled fan, I was talking about using Arduino PWM + switching transistor to control an ORDINARY fan.
Title: Re: Fan Control Theory
Post by: krupski on Dec 17, 2012, 04:14 pm

That should be fine, I've controlled a PWM fan like that, I think it was an Arctic F12 pwm too. Bear in mind that the Intel PWM spec only guarantees that fans will run from 30% pwm to maximum.


Look at what the OP said:

Quote
could I use a transistor as a switch connected to pin 3 set up so when the PWM duty cycle goes high it connect the grounds of the fans and allows me to throttle them that way?


I don't think he's talking about a PWM (4 wire) fan, but simply switching the fan on and off with the Arduino PWM output and the transistor.
Title: Re: Fan Control Theory
Post by: Dylfish on Dec 17, 2012, 11:42 pm
I was taking into account that not all fans are PWM so it might be safer to do it that way.
Title: Re: Fan Control Theory
Post by: dc42 on Dec 17, 2012, 11:46 pm


That should be fine, I've controlled a PWM fan like that, I think it was an Arctic F12 pwm too. Bear in mind that the Intel PWM spec only guarantees that fans will run from 30% pwm to maximum.


Look at what the OP said:

Quote
could I use a transistor as a switch connected to pin 3 set up so when the PWM duty cycle goes high it connect the grounds of the fans and allows me to throttle them that way?


I don't think he's talking about a PWM (4 wire) fan, but simply switching the fan on and off with the Arduino PWM output and the transistor.


Look again at his original post:

Quote
Im looking to control 3 fans (12v PC Case, Arctic f12 PWM) and i was wondering if my logic is correct.


... the Arctic F12 PWM is of course a 4-wire fan.
Title: Re: Fan Control Theory
Post by: SteveHodge on Jan 06, 2013, 05:40 pm

PC fan PWM inputs are supposed to be driven from an open-collector or open-drain output, at a frequency of 25kHz. I posted suitable code in my response to your question in the Microcontrollers section. That code has been tested on a PWM fan - an Arctic F12 PWM afair.

The best way to drive the fan PWM input is one of the following:

1. Use a small signal npn transistor such as BC337 or 2N3904. Connect collector to fan PWM input, emitter to ground, and base to Arduino PWM output pin through a 10K resistor.

2. Use a small signal mosfet such as 2N7000. Connect drain to fan PWM input, source to ground, and gate to Arduino PWM output pin (no resistor needed when driving a small signal mosfet from an Arduino pin).

The Intel spec states that the max current sourced by the PWM input is 5 mA, so wouldn't it be safe to drive it directly without a transistor/FET?
Title: Re: Fan Control Theory
Post by: dc42 on Jan 06, 2013, 06:17 pm
You are supposed to drive the fan PWM pin from an open-collector output, i.e. you can pull it low but not high. With a direct connection to the Arduino, you could achieve that using software PWM but not using hardware PWM. However, you could connect a small signal diode (preferably Schottky) between the Arduino pin (cathode) and fan PWM pin (anode) instead of using a transistor.

One other thing to consider is what happens if the Arduino is powered off but the fan is powered up. With a direct or diode connection, the fan will run at minimum speed, which may not be a safe condition. Using a transistor or mosfet, the fan will run at maximum speed.

Title: Re: Fan Control Theory
Post by: SteveHodge on Jan 07, 2013, 01:43 am
That's a good point about what happens when the Arduino is unpowered. I'd guess that in most situations you'd want the fan to run at full speed in that situation.