1

While trying to read RPM from a computer fan using the 4-wire protocol, I am getting strange readings. +12 and GND from the fan are connected to a power supply, and the tachometer to the PIN-0 or a Teensy 3.2.

I wrote code to read the tachometer pulse using the internal pull-up and interrupts. The strange thing happening is that the number of recorded revolutions is increasing as I manually slow the fan using my fingers.

Here is the code :

#include <avr/io.h>
#include <avr/interrupt.h>
#include <elapsedMillis.h>

const int fanPulse = 0;
volatile long half_revolutions;
elapsedMillis timeElapsed; 

void setup() {
  Serial.begin(9600);
  while(!Serial);

  pinMode(fanPulse, INPUT_PULLUP);
  attachInterrupt(fanPulse, rpm_fun, FALLING);

  half_revolutions = 0;  
  // analogWriteFrequency(20, 25000); // Teensy 3.0 pin 3 also changes to 375 kHz
}

void rpm_fun() {
  half_revolutions++;
}

void loop() {
  if (timeElapsed < 1000)
    return;  

  Serial.printf("%d revolutions in %d miliseconds\n", half_revolutions / 2, (unsigned long)timeElapsed);

  timeElapsed = 0;
  half_revolutions = 0;
}

Here is the strange output :

0 revolutions in 1000 miliseconds  // Start
0 revolutions in 1000 miliseconds
82 revolutions in 1000 miliseconds
394 revolutions in 1000 miliseconds  // "normal" reading
412 revolutions in 1000 miliseconds
576 revolutions in 1000 miliseconds
456 revolutions in 1000 miliseconds
554 revolutions in 1000 miliseconds
585 revolutions in 1000 miliseconds
799 revolutions in 1000 miliseconds  // Slowing the fan
712 revolutions in 1000 miliseconds
691 revolutions in 1000 miliseconds
683 revolutions in 1000 miliseconds
625 revolutions in 1000 miliseconds
531 revolutions in 1000 miliseconds
239 revolutions in 1000 miliseconds
0 revolutions in 1000 miliseconds
0 revolutions in 1000 miliseconds  // End
  • I must have misread what you have written. Why do you think these readings are strange? I would expect that as you slow the fan the number of revolutions per second goes down and that's what the results seem to say. – Code Gorilla Jun 23 '16 at 8:14
  • 1
    Did you connect the ground of the Teensy to the ground of the fan? – Majenko Jun 23 '16 at 10:57
  • Matt, I get around ~450 rpm in normal conditions and around ~650 rpm when slowing down. @Majenko, No I didn't, I was thinking this might be the issue too. My Teensy is powered through USB and the Fan to an external power adapter, is it safe to connect the two ground? Andy, the 0 rev cycles are the moment where I manually switched off the external power adapter with a switch. – malavv Jun 23 '16 at 15:40
  • 2
    You have to have the grounds connected, otherwise you are just measuring noise. – Majenko Jun 23 '16 at 15:44
  • @Majenko, make that an official response and you'll get a resolving answer! Thanks to all. – malavv Jun 23 '16 at 16:25
2

Without the ground of the teensy connected to the ground of the fan all you will be measuring is noise. Ground is required to complete the circuit between the teensy and the fan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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