Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science

20 March 2010
Author: Giorgos Lazaridis
PWM 3-Wires Fan Controller with RPM feedback (Pulse Stretching Method)

The circuit on a breadboard for test

I made this circuit for my PC System Health Monitor project. I have 4 120mm fans in my PC cabinet, each one controlled separately from a dedicated PIC. The outlet fans, are 2 Coolermaster 1200rpm fans, that are controlled using this PIC 3-Wire Fan RPM Controller. The inlet fans are 2 Zalman 1800rpm, that unfortunately did not work as expected with the same circuit. I decided to give another try to these fans with a PWM averaging rpm controller. The results were as expected. I had clear readings from the tacho of the fans, yet i could not achieve low speeds without stalling the fan, nor had i an acceptable range of speed steps. Moreover, the fan stalled once in one month of test-operation, without any particular reason.

It was time to start thinking of another way to control these fans. I did not want to change them, as the summer is coming soon, and we have some hell of a hot summer here in Greece. I will need these 1800rpm fans to work overtimes. So, the third and last way to control these fans - and have also rpm feedback is the "Pulse Stretch method".

But first, let's see the circuit in action!

What is the Pulse Stretching?

A 3-wire PC fan is orientated to work either at full speed, or with a resistor in series to reduce the voltage and thus reduce the speed. The third wire will then provide pulses with 50% duty cycle from the internal tacho. From the pulses, someone can calculate the speed of rotation.

The problem begins when the fan is powered with PWM. The tacho is directly powered from the positive and negative wire of the fan. If the fan has no constant current - e.g. powered with PWM, the tacho will not operate correct. Every time that the PWM is LOW, the tacho will not have any power at all. The result is that the feedback wire of the fan will return the PWM pulses themselves, instead of the correct rpm pulses.

The "Pulse Stretching" method works as follows. The fan is driven with high frequency PWM pulses, above 20KHz to avoid acoustic noise. Occasionally, the PWM duty cycle is turned into 100% (constant power supply). During that time, the tacho will operate normally and will return the correct rpm pulses. The constant current is kept enough time to measure one complete period of one pulse. Then, the PWM duty cycle is changed to the value it was before.

Look at the following picture of the oscilloscope. The yellow channel is the 12V PWM supply of the fan. The green channel comes directly from the fan rpm feedback. The blue channel is only for synchronization, and indicates the time that the PWM duty cycle is 100%:

During the HIGH period of the blue channel, the power supply of the fan is 12V constant. At that time, you can see that the feedback pulses are clear and can be read without any problem.

The circuit

The heart of the circuit is the PIC 16F88. The chip generates the PWM to drive the mosfet that gives power to the fan. Also, it controls the LCD. The LCD is only to display the results. When i began designing this circuit, i used an 8-pin PIC and did not have any rpm display. After all, i use the oscilloscope for this reason. The LCD was a change of the last minute.

The LED shows the sampling rate. It reads the fan speed twice a second. A normal design would never require such a fast sampling rate. You may consider reducing the sampling rate to 1 read per 3 seconds.

Finally, i use the PIC built-in A/D converter to read the position of a potentiometer. The potentiometer is connected as a voltage divider. The PIC will change the PWM duty cycle according to the position of the potentiometer. There are 2 resistors taking place in this voltage divider along with the potentiomeeter, the R6 and the R7. These resistors are carefully chosen to adjust the range of the potentiometer. With these resistors, the PWM duty cycle can be adjusted from 6% when the potentiometer is completely turned left, up to 100% when the potentiometer is turned completely to the right. Someone would ask "Why didn't you adjust the range of the potentiometer in software?". Well, yes, i could do that of course. But, i wanted this circuit to be a little bit more flexible. For example, someone can completely remove the LCD screen. Then, he gets a PIC and uploads the firmware as is, in his local store. Finally, he makes his PCB. Now, by changing these two resistors, he can adjust the minimum and maximum duty cycle - in other words, the minimum and maximum rpm speed. And all this, without having to know ANY PIC programming.

So, here is the schematic diagram of the circuit.

The time that i keep the PWM at 100% duty cycle is not fixed. I keep it that way only as long as i need to get a full reading of a complete period of a pulse. This gives me two extra advantages. First of all, the speed of the fan will not change significantly. But more important, this way will prevent the fan from stalling. If the fan stalls - something that is NOT going to happen - it will stop sending pulses to the PIC. But the PIC will send constant current to the fan to read the pulses. It will keep sending constant current until it reads one pulse! It will just NOT stall. The following image shows that i turn the PWM back on again immediately when i finish reading the pulse.

Oh and something last. If you notice, the oscilloscope reading is 13.1 Hz. This number can be turned into rpm easily. Each rotation of the fan sends two pulses. Thus, you divide the frequency by 2 to get the rps, and then multiply by 60 to get the rpm:

rpm = 13.1 / 2 x 60 =. rpm = 393

I think it is quite good for the first time, isn't is?

Following i provide the files for the PIC firmware. First, i have the complete assembly listing to read, re-compile and upload.

 Pulse Stretching PWM fan controller - Assembly listing

If you don't know how to re-compile but you do want to upload the firmware, then download the hex listing bellow:

 Pulse Stretching PWM fan controller - Hex

A slight problem

Although i could not think of this problem, when i faced it it sounds normal. If you make a large change with the potentiometer, the rpm measurement may go a little nit crazy. For example, if you are at 350rpm and you turn the potentiometer full right, the rpm will start increasing rapidly, 500-800-1000-1150-1200. But sometimes, some crazy numbers appears, like 7000rpm, just for a blink, then it returns to normal. It does not happen always that way. And usually it happen when you go from max rpm to min rpm. You should consider enriching the firmware with software filters.

Bill Of Materials
 Resistors R1 Resistor 150 Ohm 1/4 Watt 5% Carbon Film R2 Resistor 2.2 KOhm 1/4 Watt 5% Carbon Film R3 Resistor 4.7 KOhm 1/4 Watt 5% Carbon Film R4 5 KOhm potentiometer R5 2.2 KOhm potentiometer R5 Resistor 8.2 KOhm 1/4 Watt 5% Carbon Film R5 Resistor 330 Ohm 1/4 Watt 5% Carbon Film Capacitors C1 1 uF 16 Volts electrolytic capacitor Diodes D1 1N751 5.1V 400mW Zener Diode Transistors Q1 IRF520 9.2A, 100V, 0.270 Ohm, N-Channel Power MOSFET ICs IC1 PIC16F88 Microcontroller Misc LED1 LED 3mm red

Relative pages
• Learn how dimmers work
• Frequency measuring techniques
• PWM signal theory
• The voltage divider theory
• Learn about the most popular PC Cooling methods
• An intelligent self-tunned fan PWM controller
• A 2-speed PWM temperature fan controller
• How to make a PWM fan controller / LED dimmer using a 555
• Create PWM pulses with variable duty cycle controlled by a DC voltage input
• Dr.Calculus: Voltage divider calculator
• Learning PICs @ PCB Heaven On-Line Book