Author Topic: Smart fan controller (PIC based)  (Read 13586 times)

0 Members and 1 Guest are viewing this topic.

Offline DmitryLTopic starter

  • Regular Contributor
  • *
  • Posts: 242
  • Country: gb
Smart fan controller (PIC based)
« on: December 16, 2011, 12:35:53 pm »

I was changing recently a noisy fan in my Rigol scope and had to reduce fan's speed as well... Trying to find an appropriate Zener diode to put in series with the fan (guess why Zener is better than a resistor :) I thought that it would be nice to have some kind of a temperature-controlled fan that doesn't produce any noise unless it is absolutely necessary.
I also have a quite old-school bench PSU that has a big heatsink and can get really hot if I load it appropriately. Building a fan into it would solve the problem, but I didn't like having another source of constant noise.

Thus, I decided to build a simple smart fan controller, it might be useful for someone, I think.

I didn't like the idea of linear regulator, they can get hot and require large transistors, heatsinks etc. I also decided to keep away from analog design, because every instance of the controller would require calibrating and trimming.

Requirements:

    * simple schematics, as few parts as possible
    * no calibrating and trimming
    * low power dissipation => switch-mode regulation
    * temperature feedback
    * reliability
    * easy to configure for other applications.

As you can see, the lowest possible cost is not included to the list of requirements :)
So, I decided to use 8-bit PIC (PIC12f629) and DS18S20 1-wire temperature sensor from Dallas/Maxim.

Brief description:

PIC periodically polls temperature sensor on GP0 and generates PWM signal on GP5 to control the fan.  PWM duty cycle depends on the temperature measured.

DS18S20 sensor is used in "parasite power" mode because it requires just two wires; don't forget to connect sensor's Vdd and Gnd pins together as shown on the picture. The sensor poll period is about 2.5 seconds.

If controller detects that the sensor is not connected, fails to initialise or reports incorrect data, it enters "failure mode" until the problem is rectified and the temperature measured correctly. In this mode the fan's speed changes between 50 and 100% every 2.5 seconds. The idea was to make fan itself indicate the problem by changing the noise periodically, trying to attract attention to the problem :)
Another approach would be simply turning fan on 100% (but this isn't a good indicator IMHO) or use one of the spare PIC pins (I didn't bother).

PIC's GP5 pin is a PWM output that controls fan's driver. I used a NPN transistor to drive the fan, it is also possible to use a small MOSFET instead; in this case R2 is not required. Due to the switching mode of regulation the power dissipated by the transistor is very low.

PWM resolution is 4 bits, i.e. the duty cycle (and fan speed) has 16 possible values. It must be enough for controlling the fan IMHO. PWM period is about 32 milliseconds, or PWM frequency is about 100Hz. Such low frequency was selected for several reasons:
    * low range PICs (12F, 10F) do not have a built-in PWM controller, I had to implement it in software.
    * simple electronics inside the fan is designed to work with DC input voltage, fast PWM can bewilder it.
    * Fan noise increases due to PWM (see ref.[4]). On 300Hz PWM fan can produce an audible buzz, which isn't pleasant at ll;  100Hz PWM produced less noise, especially for bigger fans.
   
Of cause, the best result can be achieved with a proper buck converter, but it would require higher PWM frequency (>20KHz) and more components, like inductor, capacitor and a proper diode.

Principle of operation:

Whole possible temperature range is divided into 4 bands: -55-30, 31-45, 46-60, 61-125 degrees centigrade. Each band has a corresponding PWM duty cycle value stored in EEPROM. The temperature sensor is polled every 2.5 seconds, if it reports correct temperature, PIC reads value from EEPROM address corresponding to the temperature band and uses it to generate PWM cycles.
Also when the fan speed needs to be increased, controller gives motor a "boost" - temporarily turns it 100% on for 2.5 seconds;  this is to avoid problems with the motor start on low speed.

The temperature bands are hardcoded (I didn't see any reason to make them configurable), but the PWM duty cycle values that determine fan speed are stored in PIC's EEPROM and can be easily changed during PIC programming.

EEPROM[0] contains PWM duty cycle value for band 0 (-55-30 degrees)
EEPROM[1] contains PWM duty cycle value for band 1 (31-45 degrees)
EEPROM[2] contains PWM duty cycle value for band 2 (46-60 degrees)
EEPROM[3] contains PWM duty cycle value for band 3 (61-125 degrees)

Only 4 least significant bits of these values are meaningful (PWM resolution is 4 bits), 4 most significant bits must be 0.
The default values are:
0x00    ;-- band 0, EEPROM addr0: duty cycle 0%
0x06    ;-- band 1, EEPROM addr0: duty cycle 38%
0x0a    ;-- band 2, EEPROM addr0: duty cycle 63%
0x0F    ;-- band 3, EEPROM addr0: duty cycle 100%

You can easily change them, for example:

values 0x00, 0x0f, 0x0f, 0x0f. The fan will not work for temperatures less than 31 gedrees and will have 100% speed otherwise.
values 0x00, 0x00, 0x04, 0x0f. The fan will not work for temperatures less than 46 gedrees, 50% speed for 46-60 degrees, 100% speed above.

Notes:

I decided to write PIC firmware in assembler, just for fun, I was a bit tired of C++ and decided to have a little rest :)

I think that the program can be quite easily ported to even lower PIC family, like PIC10; the problem is that they do not have EEPROM for storing duty cycle values. These values can be easily hardcoded in to PIC ROM anyway.

A lot of PIC IO pins are left unused. It's also possible to assign them some functionality, like overheat/sensor error indication etc. I tried to keep everything as simple as possible and didn't do that.

PIC code itself isn't 100% reliable IMHO. Even if it uses WDT, there are some places when it can potentially enter the infinite loop due to  some hardware glitch and stay there forever (e.g. wait procedures). Getting rid of this would require redesigning whole program, making it a state machine where every possible state can't last longer that WDT period. I didn't bother much :)

It is also possible to make hardware a bit more reliable to address the cases that usually never happen.
Add 10K resistor between PIC's GP5 and ground to prevent VT1 opening if PIC isn't present or hung when GP5
is configured as input. Add 33 Ohm resistor in series with GP0 to prevent damage if the sensor's bus accidentally
shorted.

References:


[1] DS18S20 High-Precision 1-Wire Digital Thermometer
[2] Maxim AN1784. Fan Speed Control Is Cool!
[3] T.C.Lun Microcontroller for Variable Speed BLDC Fan Control System.
[4] Microchip AN771. Suppressing Acoustic Noise in PWM Fan Speed Control Systems
 
The following users thanked this post: razvanm

Offline steaky1212

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
Re: Smart fan controller (PIC based)
« Reply #1 on: December 16, 2011, 03:32:18 pm »
I would have thought the DS18S20 is more than you need given you are purely using 4 temp bands.
Surely you could use a thermistor instead.

Awesome idea though - I nearly made one for PC, but the PWM noise from the fan was annoying. I should have filtered the output but I didnt. Plus, I was trying to get the speed back too - and iirc you get issues when doing PWM as you are cutting the power out (or something).
 

Offline McMonster

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: pl
    • McMonster's blog
Re: Smart fan controller (PIC based)
« Reply #2 on: December 16, 2011, 06:26:51 pm »
I wanted to make a PC fan controller for a home server and have the schematic almost finished, but didn't have the time to build it. But I used AVR with four channels (three wire fan connectors), DS18B20 sensors and RS232 feedback to the machine. I've also used molex connector for power directly from ATX PSU. I should have plenty of free time next week, so maybe I'll actually build it.
 

Offline DavidDLC

  • Frequent Contributor
  • **
  • Posts: 755
  • Country: us
Re: Smart fan controller (PIC based)
« Reply #3 on: December 17, 2011, 12:38:36 am »
You may need to have a big capacitor at the regulator output, otherwise the VCC can fluctuate due the PWM variation and you can have reset or some other problems on your system.

David.
 

Offline DmitryLTopic starter

  • Regular Contributor
  • *
  • Posts: 242
  • Country: gb
Re: Smart fan controller (PIC based)
« Reply #4 on: December 17, 2011, 01:31:46 pm »
You may need to have a big capacitor at the regulator output, otherwise the VCC can fluctuate due the PWM variation and you can have reset or some other problems on your system.

No need, actually. Motor's rotor mass works as an intergrator. The only problem here is the slightly increased noise caused by fan's power switching ON and OFF due to PWM. It can be made less by making PWM front edge less steep, but it will make the transistor work in linear mode -> heat and much less efficiency.
 

Offline razvanm

  • Contributor
  • Posts: 23
  • Country: ro
Re: Smart fan controller (PIC based)
« Reply #5 on: June 08, 2017, 03:37:03 pm »
I started to build this project and so far I have the PCB and components ready. The plan is to have two temp sensors monitoring two different radiators but start the fan in case any of the sensors will reach the threshold.
DmitryL or someone else can please give me a hint on the source code modifications to include the second DS18S20?

Thanks
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5018
  • Country: ro
  • .
Re: Smart fan controller (PIC based)
« Reply #6 on: June 08, 2017, 03:47:53 pm »
Microchip has some fan controllers they got through an acquisition of another company.

Have a look at EMC2103-1 : http://ww1.microchip.com/downloads/en/DeviceDoc/20005250.pdf

It has pins for external diode and you talk to the chip using SMBus to read rpm and set rpm and read internal ic temperature and external temperature (from external diode)
It's 3.3v ..3.6v part but has 5v tolerant pins .. and it's not expensive.
 

Offline razvanm

  • Contributor
  • Posts: 23
  • Country: ro
Re: Smart fan controller (PIC based)
« Reply #7 on: June 08, 2017, 03:50:36 pm »
Marius, thanks but as I said I already have the PCB and parts. I'm not going to change the whole project when I can adjust a piece of code to adapt the second sensor.
 

Offline ZeTeX

  • Frequent Contributor
  • **
  • !
  • Posts: 610
  • Country: il
  • When in doubt, add more flux.
 

Offline razvanm

  • Contributor
  • Posts: 23
  • Country: ro
Re: Smart fan controller (PIC based)
« Reply #9 on: June 10, 2017, 08:43:22 pm »
ZeTeX, thanks but I'm using two SanAce 80mm fans, each rated @ 1.1A at full speed. Linear regulators are out of the question. PWM FTW! :)
 

Offline ZeTeX

  • Frequent Contributor
  • **
  • !
  • Posts: 610
  • Country: il
  • When in doubt, add more flux.
Re: Smart fan controller (PIC based)
« Reply #10 on: June 10, 2017, 09:30:39 pm »
ZeTeX, thanks but I'm using two SanAce 80mm fans, each rated @ 1.1A at full speed. Linear regulators are out of the question. PWM FTW! :)
Usually, the current that is written on the label on the fan means the inrush current, try to actually measure the current and see.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf