3
\$\begingroup\$

I am working a PIC µC project. I am using 12VDC PC fan (Coolermaster) for my application. A part of the project is to return the RPM from the third wire of the fan to an LCD.

First of all, How can I read the signal? Is it a sort of pulses every rotation? Also, Do I need to use an ADC pin or just a Digital one would suffice? I found lots of diagrams telling to connect a pull up resistor to +5V. Why?

A sample code of how this works will be helpful.

Thanks.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ What fan are you working with. most CPU fans don't provide a Tach signal(signal generation wire) on the output. most fans have a Controlling wire(colors vary, but usually blue). If you are trying to get an accurate rpm number you may need to use a reflective optical sensor to read the tach \$\endgroup\$ May 17, 2013 at 16:14
  • \$\begingroup\$ Also if the wire color is yellow or green, it is a signal wire to use with your control wire usually. These signal wires typically run at a fixed frequency, here is a fan I purchase from Jameco that is typically in Dell PC's \$\endgroup\$ May 17, 2013 at 16:22
  • \$\begingroup\$ @Ashitakalax .. It is not a CPU fan. It is a case fan. They have no color since they are sheathed, but I think it is the wire which reports RPM of the fan. I have connected this wire to a Voltmeter -adjusted to AC measurement- and I observed the following: - When the fan is not turning ON, the voltmeter reads the highest value. When it is at 12VDC full speed, the voltage is stable, as soon as I start to decrease the voltage to the fan, the readings starts to fluctuate. Is that an alternating signal (pulses) behavior? \$\endgroup\$ May 17, 2013 at 19:11
  • \$\begingroup\$ It is hard to imagine that they would make a analog output on the fan. If you have an Oscope(oscilloscope) you can determine whether it is a pwm signal or a tach signal. It sound like it would be a tach signal. if it fan is off, and the signal is high(1). Then I would guess the it would it is pulled low once per revolution. You can try and spin the fan by hand while it is not running(but ON). You should (probably) see the signal pull low at some point while turning it. \$\endgroup\$ May 17, 2013 at 19:33

5 Answers 5

4
\$\begingroup\$

Reading the signal

enter image description here

The main point to notice is that the tach output from the 3 wire fan switches from 0 to 12V. If connected directly to the input of the PIC it would exceed the voltage rating of the device. Connecting the tach output to a 5V supply through a resistor would not prevent it from exceeding 5V as that resistor would simply form a potential divider with R1 and leave the tach output sitting at a voltage between 12 and 5 volts. A quick check with an oscilloscope or voltmeter would verify this voltage.

To reduce the output to a 0 - 5V pulse suitable for the PIC input you could:

(i) Use a resistor (R2) across the output (a slightly smaller value than R1) to give a maximum 5V at the output (quick and dirty solution) ( R2 should be about 0.7 R1 to give a 5V output)

(ii) Connect a small signal npn transistor - base to the tach output. Connect a pull up resistor from its collector to 5V. Emitter to ground. Take the new tach (inverted) output from the collector to the PIC input line.

(iii) Connect an opto isolator with a pull up resistor to the 5V line (pin 2, 4 to ground (0V) , pull up resistor from 5V to pin 5. Take output from pin 5. Pin 6 is left unconnected) This circuit will invert the pulse signal but as you are counting pulses it does not matter. It also protects the PIC input from exceeding 5V.

enter image description here

\$\endgroup\$
4
  • 2
    \$\begingroup\$ This might be relevant to the ultimate project, but doesn't seem to be an answer to any of the questions that were actually asked. \$\endgroup\$ May 17, 2013 at 15:02
  • \$\begingroup\$ Comment noted and answer revised \$\endgroup\$ May 17, 2013 at 19:00
  • \$\begingroup\$ @JImDearden, You are completely right. My tach was signal was very messed up. It seems the fan has no resistor built in between the + and the Tach. After connecting a 10K resistor, the tach output was 6.5V around 12V power supply. I decided to connect to connect 2.2M ohm resistor between the + and the tach to get exactly 5V at 12.2V power supply. Thanks a lot. \$\endgroup\$ May 21, 2013 at 2:03
  • 1
    \$\begingroup\$ Even simpler: put a small diode between the tacho pin and your MCU, with the anode at the MCU end. That way, the tacho can only pull down your MCU pin and behaves like an open-drain output even if the fan includes a pullup R. Then enable weak pullups in the MCU port or put a 10k R between your MCU pin and VCC, and there you go. \$\endgroup\$ Jan 29, 2016 at 2:27
6
\$\begingroup\$

The safest way is to force the fan tacho output to behave only as open-collector by adding a diode and then using your own pullup:

schematic

simulate this circuit – Schematic created using CircuitLab

That way it doesn't matter if the fan has a pullup resistor or what its supply voltage is, it cannot pull your MCU pin too high. You can use the "weak pullup" functionality on your MCU pins if it supports them, or add an external resistor as pictured.

Computer fans usually produce 2 pulses per revolution but there are variations. Even a fairly fast fan (6000RPM) is only 100Hz, which means pulses at 200Hz. The usual way to measure speed is to use an "input capture" feature on a timer, i.e. leave a free-running timer going fairly fast (tens of kHz) configured to capture the timer value on the falling edge of the input, then subtract consecutive captured values in order to measure the time between pulses. Don't forget you also need to catch the timer-overflow interrupt and figure that into your period calculations.

\$\endgroup\$
1
  • \$\begingroup\$ Seems to be the simplest and cheapest solution. Is there by any chance a scenario when VCC coming to the 12v rail through R2-D1-R1 might be a problem? \$\endgroup\$
    – grabantot
    Aug 28, 2016 at 9:05
4
\$\begingroup\$

Here's a specification for 4-wire (PWM controlled) fans from formfactors.org "brought to you by Intel": http://www.formfactors.org/developer%5Cspecs%5C4_Wire_PWM_Spec.pdf

Tachometer Output Signal Fan shall provide tachometer output signal with the following characteristics:

  • Two pulses per revolution
  • Open-collector or open-drain type output
  • Motherboard will have a pull up to 12V, maximum 12.6V

Note that the pull up is supposed to be on the motherboard, i.e. not on the fan.

\$\endgroup\$
2
\$\begingroup\$

Typically, the third (tach) wire is grounded "n" times per revolution, where "n" varies between fan models, but typically 2 or 4 times per revolution. (The data sheet fro the fan should specify this.)

You will need to add a pull-up resistor to give you a square wave signal which you can feed into a digital input. You will need to measure the period of the square wave or count transitions per second to compute the RPM.

For example, assume 6000RPM and 4 pulses per revolution, you will see 400 pulses per second and the average period of a pulse (leading-edge to leading-edge) would be 2.5ms (1/400).

As for actually reading the pin, the easiest way would be to set up an interrupt on a transition (either up or down) and record the value of a high resolution timer in a buffer, which you can read in your main line to compute average period over several cycles. Alternatively, you can loop pooling the pin looking for changes and record the timer values.

Edit: Jim Deardan correctly notes that on most fans, the tach wire is already pulled up to +12V and the voltage needs to be reduced before connecting to an input on the PIC. Please read his comment.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the answer. Unfortunately, no datasheet is available, however I know the maximum RPM 2000 RPM ± 10% @12VDC, so I may try all combinations from 1 to 4 times per revolution till record the closest value to the claimed maximum RPM. Secondly, Shouldn't I connect the Tach wire to an external interrupt pin? \$\endgroup\$ May 17, 2013 at 19:24
1
\$\begingroup\$

Elaborating on DoxyLover's answer. You can use the Capture/Compare/PWM (CCP) module for this. Basically the capture mode does exactly what DoxyLover described, it records the value of a timer based on a programmable event on a pin (in this case, you probably want it to record the falling edge). So you can have the associated timer run, have the module record the timer value on the falling edge, and then read the value of that capture register at your leisure. This way you don't have to have an interrupt for every time the fan contact is pulsed, and also the result is not dependent on things such as interrupt latency.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, I was going to use External Interrupt and but since you may have offered a better solution. How can I use the CCP to capture the RPM signal instead of using External Interrupts? \$\endgroup\$ May 17, 2013 at 19:31
  • \$\begingroup\$ Thanks for adding that. I am not directly familiar with the PIC so I answered generally. Your addition should be useful to the OP \$\endgroup\$
    – DoxyLover
    May 17, 2013 at 22:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.