Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

8 July 2011
Author: Panagiotis Kalogeris
PC Fan RPM Bargraph Meter and Failure Alarm with PIC


This is the first circuit designed by a PCB Heaven reader!

I'm really very happy to present this circuit! This is a very special page, and what's special about it is that this circuit is designed NOT by me, but from a PCB Heaven reader, which happens to be also one of my students in my PIC classes. As a matter of fact, he is my first student... Well, ok, he is my only student :). So, this is the very first circuit page that i host in my site which is designed by a PCB Heaven reader. Special thanks to Panagioti Kalogeri, which you will find him trolling around my site with the id _Pike...

This circuit is the result of an exercise that i asked him to make, in order to practice with the Timer modules of the PIC. The PIC will read the tacho output of a PC fan. The rpm is then translated into a number of LEDs turned-on on the bar-graph. The minimum rpm during which only one LED is turned on is 600 rpm, and the maximum is 1200 - which is also the max speed of the fan. Panagiotis was asked to implement the rpm measurement with the Reverse Frequency Measuring as described here.






The Circuit

Here is the circuit designed by Pike: (click to enlarge)





The fan is a typical 12V PC fan with 3 (or 4 wires). The tacho wire (usually comes in yellow color) is connected to the LSP1 pad.

The operation is as follows: The pulses from the tacho of the fan are decreased to 0-5 volts with the zener diode, and then are driven to the input RA4 of the 16F628 PIC. The software resets and starts the Timer0 module, and waits for a full pulse period on that input (from the fan RPM feedback). After completion of a full pulse period, the PIC compares the Timer0 register with 10 predefined values, according to which, the PIC will turn on or off the LEDs on the bar-graph.




Bill Of Materials - Original circuit
Resistors
R1-10Resistor 330 Ohm 1/4 Watt 5% Carbon Film 
R11Resistor 2.2 KOhm 1/4 Watt 5% Carbon Film 
R12Resistor 4.7 KOhm 1/4 Watt 5% Carbon Film 
Capacitors
C1Electrolytic Capacitor 1 uF 50 Volts
C2Electrolytic Capacitor 1 uF 50 Volts
Diodes
D11N751 5.1V 400mW Zener Diode 
Integrated Circuits
IC1PIC16F628 Microcontroller 



The New Circuit (Updated 5/11/2011)

Panagiotis sent me an improved circuit for this project. Here is the schematic:

~~~~ ATTENTION ~~~~ (26/1/2015) I JUST NOTICED A MISTAKE IN THE SCHEMATIC REGARDING THE ADDED BUTTONS. I have already contact Panagiotis. If he still has the corrected schematics i will upload them. Meanwhile, you can feel free to use the PCB design as it is tested and works. Bummer.



What's new:

At first, Panagiotis added an 7805 to regulate the 5v supply required for the microcontroller. Now the circuit requires only 12 volts to operate. Also, he changed the rpm feedback input from the fan. He connected the pull-up resistor to the 5V instead of 12, so now the zener diode can be omitted.

A transistor driver and a relay was added for failure alarm. If the fan stalls or if the fan rotates at very low speeds for more than 3 seconds, the relay is activated. The relay has 12V coil power directly from the 12v power input. You may wanna use a 5V relay, so you can connect pin1 of the relay to the output of the 7805. There are 2 modes for the alarm: The temporary and the persistent. In temporary mode, the alarm is deactivated automatically (relay is disarmed) if the fan starts rotating again. In persistent mode, the alarm is deactivated only if the operator clicks the button (another addition). The alarm mode can be changed by the jumper: If the jumper is closed, the circuit operates in persistent mode, otherwise it operates in temporary mode.

Finally, he added a fan-adaptivity mode, and now the circuit can operate with fans that revolve at different speeds. Here is how it works: If the button (that resets the alarm) is kept pressed upon start-up, then the circuit is driven in adaptivity mode. It waits for 5 seconds until for the fan to revolve at full speed. Then, it measures the fan's speeds and scales the LEDs accordingly. The value is saved into the EEPROM and the circuit will use these values to indicate the rpm. At full rpm, all LEDs are on, while at half RPM, only 2 LEDs are on.




Bill Of Materials - New Circuit (5/11/2011)
Resistors
R1-10Resistor 390 Ohm 1/4 Watt 5% Carbon Film
R11Resistor 2.2 KOhm 1/4 Watt 5% Carbon Film 
R12Resistor 4.7 KOhm 1/4 Watt 5% Carbon Film 
R13Resistor 390 Ohm 1/4 Watt 5% Carbon Film
R14-15Resistor 10 KOhm 1/4 Watt 5% Carbon Film 
Capacitors
C1Electrolytic Capacitor 4.7 uF 50 Volts
C2Electrolytic Capacitor 100 uF 50 Volts
Diodes-Transistors
D11N4004 General Purpose Diode Rectifier 
Q1BC338 NPN Silicon AF Transistors 
Integrated Circuits
IC1PIC16F628 Microcontroller 
IC27805 Positive Voltage Regulator 



How to calculate these values?

I find it very interesting to explain how to calculate these values, mainly to prove once more the power of mathematics. So, let's begin with the fan itself. Like all PC Fans (read how PC Fans work), this fan produces 2 pulses per one full revolution. The upper limit is 1200 rpm, which means 1200 full revolutions per minute. If during one revolution the fan sends two pulses, then in 1200 revolutions it will produce 2400 pulses (1200x2). So, in 1200 revolutions per minute (RPM), we will get 2400 pulses per minute (PPM). To convert this value into pulses per second (AKA Hertz), i only have to divide it by 60 (because one minute has 60 seconds). 2400/60 = 40. In other words, when the fan runs at full speed (1200 rpm), the tacho output will produce pulses of frequency 40 Hz. Similarly, when the fan runs at 600 RPM, the tacho output will be 20 Hz.


The Bar-graph

Later on, we will need to use these frequency values in terms of period. The period of a signal, is actually the inverse of it's frequency. The general formula is:


F [Hz]1
T [Sec]

So, to convert the frequency (F) into period (T), i only have to inverse it (1/F). The period of the 40 Hz is 1/40 = 0.025 Sec, and the period of the 20 Hz is 1/20 = 0.05 Sec. Keep that in mind because we will be needing them.

Now, let's see how the PIC measures this frequency. Pike has set the Timer0 module to increase with each instruction of the PIC, through a 1:256 prescaller. The internal oscillator is 4MHz, and as known, the instruction cycle is one quarter of the oscillator, so it is 1Mhz (4Mhz/4), or 1.000.000 instructions per second. The prescaller will divide this number by 256. 1.000.000/256=3906,25. So the Timer0 register module increases 3906 (integer of 3906,25) times every second.

And here comes the good part. The Timer0 module is increased ONLY as long as a full pulse period lasts! And how much is that? We calculated it before! At full RPM, a full period lasts 0.025 seconds. We can hence calculate the number of pulses that the Tmr0 will measure when the fan runs at full rpm:



Tmr01200 = 3906 x 0.025 = 97,65 = 97 (integer).

Similarly, we can calculate the Tmr0 count when the fan runs at 600rpm:



Tmr0600 = 3906 x 0.05 = 195,3 = 195 (integer).

First thing you may notice is that the count at 600 rpm is greater than the count at 1200 rpm, which sounds kinda weird but it is not. It is absolutely normal, considering the fact that at 1200 rpm the pulse period is less than the pulse period in 600 rpm... You may want to read more about frequency measuring in general...

Now we are getting somewhere. There are 10 LEDs on the bargraph which we want to turn on or off according to the RPM from 600 to 1200. In other words, we want the LEDs to light according to the Tmr0 count, which can be from 97 to 195. We can calculate the step easily:



S = (195-97) / 10 => S = 9.8

So, we can use a step of 10, but that is not standard. We could have a smaller step for higher RPM and bigger step for lower RPM. That is totally up to what effect we want the bargraph to generate.




The PIC Firmware

Here is the assembly listing for those who want to change and re-compile the code, and the HEX file to simply upload and run. Version 2 applies works with the second (new) circuit (5/11/2011)


 PC Fan RPM Bargraph Meter - Assembly listing - V2.0

 PC Fan RPM Bargraph Meter - HEX File - V2.0


Version 1 works with the original circuit (first).


 PC Fan RPM Bargraph Meter - Assembly listing - V1.0

 PC Fan RPM Bargraph Meter - HEX File - V1.0



The PCB

I usually do not make PCBs for my circuits, since i make them for educational or testing purposes. But Panagiotis designed a nice and tight PCB for his design. Here is the PCB board and parts layout:


 PC Fan RPM Bargraph Meter - PCB and Parts Layout - V1.0



This is the PCB drilled. We etched it together in the pcbheaven techlabs. Panagiotis did a nice job soldering the parts The PCB looks fine indeed. The 7805 placed horizontally was not a bad idea after all.


I was accused that i changed the PIC fuses when i programmed the PIC and that i enabled the MCLR pin. This gave Panagiotis a headache, because he had the MCLR pin turned off, so when he designed the PCB the MCLR was not pulled high, thus the PIC failed to operate. Well, i now formally answer to these strictures:


"Practice makes perfect"

After this "slight" delay, the PCB worked sweet:











Comments

  Name

  Email (shall not be published)

  Website

Notify me of new posts via email


Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


      

  • At 21 May 2015, 16:22:44 user Mike S. wrote:   [reply @ Mike S.]
    • I'm back to give you an update. I purchased a hall effect sensor module that was made for Arduino, it runs on 5VDC and uses a A3144 hall effect sensor with a LM393 chip. The outputs are Analog and Digital, and I was able to get a reading using the Digital output connected to simulate the RPM signal.
      If anybody is looking to monitor the RPM of a fan and it doesn't have that RPM wire, this is a solution. In my case, I needed to monitor an industrial fan (not a computer fan) that runs on 110VAC and is almost 20 inches in diameter. By combining the above mentioned hall effect module with this great project from PCBHeaven, you can monitor the RPM of just about anything that spins!


  • At 1 May 2015, 10:23:30 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Mike Most likely you need to interface the sensor to the circuit in some way.


  • At 14 April 2015, 7:02:23 user Mike wrote:   [reply @ Mike]
    • Hi Mr. Giorgos, I have tried to use the hall effect sensor (a3144) with magnets like I mentioned to you in a previous message, and have not being able to make that work. It's the only thing left for me to figure out for my project, and it's taking me a long time since I don't have much experience in electronic engineering. I was hoping you could guide me in the right direction. I powered the sensor correctly, and connected directly to what would be the RPM wire on the fan, pin3 on the pcb, and haven't been able to get a reading in any way. The magnets are connected to the end of the plastic blades of the fan, 2 magnets in total. The fan I use should have an average of 1400rpm. Thanks in advance for any advice you can give me! Mike


  • At 20 February 2015, 6:54:18 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Mike S. Good to hear. Hehehehe no we do not accept donations. We are happy to have you with us.


  • At 19 February 2015, 19:47:19 user Mike S. wrote:   [reply @ Mike S.]
    • IT WORKED!!! I discovered the old fan I was using had a bad rpm wire, I swapped with a new one and it's now working as it should. I followed the PCB parts and drawings like you told me. Many thanks for your help. Also, do you accept donations? :)


  • At 19 February 2015, 16:00:08 user Mike S. wrote:   [reply @ Mike S.]
    • After referring to the PCB I noticed the resistors are also different values than the parts list, ex: on the PCB I can see 3 10K resistors, but the parts list calls for 2 only. Also, I received my programmer and parts that I had ordered for this project, and after putting it all together I only get 2 LEDs to light up. If I start the board with the button pressed, all LEDs come on, but drop out within about 5 seconds. If I stop the fan, the 2 LEDs remain on... Do the resistors have anything to do with it? I built exactly like the PCB picture, and have wired my board twice to make sure it's correct. Any suggestion is appreciated. My fan is a normal computer fan, 12V, 3 wires. Thank you.


  • At 6 February 2015, 20:41:50 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Mike S. Well, yes you could. But it sounds like a really hardcore mod!


  • At 3 February 2015, 19:05:40 user Mike S. wrote:   [reply @ Mike S.]
    • Thanks for the update, I will refer to the PCB drawing.
      One last question: If my fan doesn't have the RPM wire, can I use a hall effect sensor (a3144) with magnets to provide the RPM data?


  • At 26 January 2015, 21:29:44 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Mike S. Actually you only need to connect the 3 wires from the PIC lead of the switch input together (pin18). But looking through the schematic i discovered a funny mistake that Panagiotis made. The circuit works because I helped him to develop the PCB, but this schematic is definitely wrong. So, follow the PCB and NOT the schematic. I hope that Panos will see this post and he will send me the correct schematic to upload.


  • At 24 January 2015, 23:30:41 user Mike S. wrote:   [reply @ Mike S.]
    • If anybody can help, I need to monitor 3 fans, so I'm building 3 kits, one for each fan. My question is, how could I have just one reset switch instead of 3, can I wire the reset switches of each kit all together? This would mean to wire all three pin 14 together, and all pin 18 together, wired to a single switch, correct? Will that work?


  • At 15 September 2013, 7:16:59 user Panagiotis Kalogeris wrote:   [reply @ Panagiotis Kalogeris]
    • Hello panagioti did you manage to make it work?


  • At 16 March 2013, 20:13:20 user Panagiotis wrote:   [reply @ Panagiotis]
    • Hello.I have the same problem.i need a help for to display the rpm on leds.. i don't know how to do that.. can you send me details about that please.I think I have done the circuit and programming correct. only 2 leds is on.


  • At 18 February 2013, 18:48:28 user ashok wrote:   [reply @ ashok]
    • i need a help for to display the rpm in lcd.. i dont know how to do that.. please semd details about that


  • At 28 October 2011, 15:16:07 user Kammenos wrote:   [reply @ Kammenos]
    • @saikhamhein if they have the same pinout, then you can give it a try.


  • At 28 October 2011, 15:09:13 user saikhamhein wrote:   [reply @ saikhamhein]
    • Can I use this program on pic 16f84a directly? Thank You.


  • At 9 August 2011, 17:25:08 user de.das.dude (sayan) wrote:   [reply @ de.das.dude (sayan)]
    • kudos to PCBheaven!
      more computer fan ckts plz :D


  • At 19 July 2011, 17:04:38 user Panagiotis wrote:   [reply @ Panagiotis]
    • Hello stefan thank you for your good comment.I use assembly...(I dont know if you mean the same) and then i use the microchip's assembler (Mplab) to convert the asm file to hex.take a look here if you are not familiar with....

      http://pcbheaven.com/picpages/MPLAB-Environment/

      Kam has made an excellent job....If someone want to ask anything about programming please feel free to ask to the topic

      Learning the PIC micro-controller PCB Heaven - On line book discussion
      of the forum.


  • At 16 July 2011, 21:50:17 user Stefan wrote:   [reply @ Stefan]
    • Good job _pike.Do you use assembler?


  • At 8 July 2011, 21:27:26 user _pike wrote:   [reply @ _pike]
    • or the pic.... (Please kam can you include this comment with my comment before since i cannot edit my comment? Thanks! :-) )


  • At 8 July 2011, 21:12:57 user _pike wrote:   [reply @ _pike]
    • Hello sometimes it is very boring to carry my power supply to the room i work to.I have a small house and i can't have a laboratory :-( . So i use a battery to supply my experimental circuits.In the photo above there is a separate power sypply since the pc fan needs 12v to get the full rotation.As for the values of the leds resistors,you can choose your values according to your wish,but remember to choose a value that will not burn the leds


  • At 8 July 2011, 15:51:08 user Kammenos wrote:   [reply @ Kammenos]
    • @Fung yes they are different, but it works without any problem no matter which one you choose. And there is no battery. Pike's board has a 9V battery case but currently is not used.


  • At 8 July 2011, 13:54:36 user Fung wrote:   [reply @ Fung]
    • The values of R1-10 in BOM are different from the circuit diagram and the photo, aren't them?

      And what is the purpose of the 9V battery case which is shown in the first photo?



    delicious
    digg
    reddit this Reddit this
    Faves



     HOT in heaven!


    NEW in heaven!



    New Theory: AC electric motor working principle



     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy