evilkitty
Posts: 370
Joined: Tue Apr 15, 2014 11:39 pm

Reading PC fan tachometer

Tue Apr 21, 2015 9:29 pm

What i want to do is control a 3pin fan using PWM
what i need to do to my understanding for that is use a resistor and a NPN transistor to control the speed
For a 4pin fan i would simply connect the PWM output to the fans PWM input wire (not sure if safe to do with the fan @12v)

Now reading the fan is where i am a bit confused
i did some reading i found i can use a cheap 74HC4040 chip to count the interruptions from the tachometer and read it
what i would like is a breadboard friendly chip to count the interruptions from the tachometer and let my device read that value
i was hoping to use something easy for like a 1 wire chip (like the DS1820B works)

my end goal is a working software managed fan controller i can add in my linux desktop (motherboard just don't let you control fans based on the GPU temp via BIOS and never have enough fan plugs)

i don't need help with the software side, that part is easy for me
i just don't want to buy the wrong part and have to get another and pay shipping again or worse and fry something
My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

User avatar
joan
Posts: 14004
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Reading PC fan tachometer

Tue Apr 21, 2015 9:43 pm

I thought the fan output signal was an open collector and pulsed twice per revolution. I'm fairly sure I've checked this several times with PC fans.

In other words you should be able to connect the wire to a Pi gpio, set the gpio's internal pull-up to 3V3 and then read the pulses. The gpio will normally read 1 but will read 0 twice a revolution.

Do a google for PC fan open collector output.


evilkitty
Posts: 370
Joined: Tue Apr 15, 2014 11:39 pm

Re: Reading PC fan tachometer

Wed Apr 22, 2015 12:02 am

joan wrote:I thought the fan output signal was an open collector and pulsed twice per revolution. I'm fairly sure I've checked this several times with PC fans.

In other words you should be able to connect the wire to a Pi gpio, set the gpio's internal pull-up to 3V3 and then read the pulses. The gpio will normally read 1 but will read 0 twice a revolution.

Do a google for PC fan open collector output.
so basically just run a inf loop really fast and count the times it is high/low (assuming the unit can take enough reading a second)
this would eat the processing power available
id need at least 34 checks per second to detect all pulses (based on 1000 rpms)
i do plan on using a ff32 chip's gpio pins for this - https://www.youtube.com/watch?v=pQHyYEsvemc
My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

User avatar
joan
Posts: 14004
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Reading PC fan tachometer

Wed Apr 22, 2015 8:14 am

You can easily count that number of pulses.

My pigpio library reads the gpios 200,000 times a second by default.

What programming language do you want to use?

The following Python has no problem with 8000 pulses per second on a Pi2.

Code: Select all

#!/usr/bin/env python

import time

import pigpio

FAN_GPIO=4

pi = pigpio.pi() # Connect to local Pi.

callback = pi.callback(FAN_GPIO) # Create default tally callback.

start = time.time()

last_count = callback.tally()

while (time.time() - start) < 100.0:
   count = callback.tally()
   print("counted {} pulses".format(count - last_count))
   last_count = count
   time.sleep(1.0)

callback.cancel()

pi.stop() # Disconnect from local Pi.
Tested with

Code: Select all

$ pigs p 4 128 # square PWM on gpio 4
$ pigs pfs 4 10 # set PWM frequency to 10 Hz
10
$ # Now start fan.py
$ pigs pfs 4 20
20
$ pigs pfs 4 40
40
$ pigs pfs 4 80
80
$ pigs pfs 4 160
160
$ pigs pfs 4 200
200
$ pigs pfs 4 400
400
$ pigs pfs 4 500
500
$ pigs pfs 4 800
800
$ pigs pfs 4 1000
1000
$ pigs pfs 4 2000
2000
$ pigs pfs 4 4000
4000
$ pigs pfs 4 8000
8000
$ pigs pfs 4 1000000
8000
$ 

Code: Select all

paul /ram $ ./fan.py
counted 0 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 10 pulses
counted 12 pulses
counted 20 pulses
counted 20 pulses
counted 20 pulses
counted 20 pulses
counted 20 pulses
counted 23 pulses
counted 40 pulses
counted 40 pulses
counted 40 pulses
counted 40 pulses
counted 59 pulses
counted 80 pulses
counted 80 pulses
counted 80 pulses
counted 80 pulses
counted 80 pulses
counted 129 pulses
counted 161 pulses
counted 160 pulses
counted 160 pulses
counted 160 pulses
counted 160 pulses
counted 182 pulses
counted 200 pulses
counted 200 pulses
counted 200 pulses
counted 201 pulses
counted 200 pulses
counted 339 pulses
counted 401 pulses
counted 400 pulses
counted 401 pulses
counted 400 pulses
counted 401 pulses
counted 479 pulses
counted 500 pulses
counted 501 pulses
counted 500 pulses
counted 501 pulses
counted 501 pulses
counted 759 pulses
counted 800 pulses
counted 801 pulses
counted 801 pulses
counted 800 pulses
counted 965 pulses
counted 1001 pulses
counted 1001 pulses
counted 1001 pulses
counted 1001 pulses
counted 1001 pulses
counted 1002 pulses
counted 1687 pulses
counted 2002 pulses
counted 2001 pulses
counted 2004 pulses
counted 2002 pulses
counted 2002 pulses
counted 2002 pulses
counted 2004 pulses
counted 3353 pulses
counted 4006 pulses
counted 4010 pulses
counted 4004 pulses
counted 4008 pulses
counted 4005 pulses
counted 4005 pulses
counted 7192 pulses
counted 8006 pulses
counted 8009 pulses
counted 8010 pulses
counted 8005 pulses
counted 8005 pulses
counted 8010 pulses
counted 8006 pulses
counted 8006 pulses
counted 8004 pulses
counted 8004 pulses
counted 8010 pulses
counted 8002 pulses
counted 8010 pulses
counted 8009 pulses

evilkitty
Posts: 370
Joined: Tue Apr 15, 2014 11:39 pm

Re: Reading PC fan tachometer

Wed Apr 22, 2015 11:11 am

any idea how long the pulses are?
probably php, shell, or python (probably python)
My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

User avatar
joan
Posts: 14004
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Reading PC fan tachometer

Wed Apr 22, 2015 11:24 am

evilkitty wrote:any idea how long the pulses are?
probably php, shell, or python (probably python)
Not really. I guess it would depend on how fast the fan is rotating unless the fan artificially latches the pulse. Perhaps the fan standard specifies a minimum.

If the fan is plugged into a motherboard you can't connect the tacho by a simple spur to the gpio as the PC motherboard will be pulling the line up to 12V. You can only do this if the only pull-up is from the Pi.

Return to “Automation, sensing and robotics”