Go Down

Topic: Strange issue when reading Fan tacho using pulseInLong() (Read 399 times) previous topic - next topic

jone886

Hi Everyone,

I am having this strange issue when using Arduino Uno to read a pulses using the pulseInLong() function. I am using a Noctua NF-F12 2000RPM 4 Pin PWM fan, and the only wire i connected to Uno pin 2 is the Green (3rd pin) of the fan.

When i disconnect the 12v supply to the fan, the Uno still picks up a frequency of 50Hz from pin 2. When i hook up the 12v supply, the reading is all over the places. Note: reading is the same if i put a 10k pull up resistor.

Can someone please pick up any silly mistake i have made? thank you very much

Code: [Select]
int pin = 2;

unsigned long high, low;
float f;

void setup()

{
  Serial.begin(9600);
  pinMode(pin, INPUT);
}

void loop()

{

  high = pulseInLong(pin, HIGH);
  Serial.print("High: ");
  Serial.println(high);
  delay(1000);
  
  low = pulseInLong(pin, LOW);
  Serial.print("Low: ");
  Serial.println(low);
  delay(1000);

  f=1.0/((high + low)*1e-6);
  Serial.print("Hz: ");
  Serial.println(f);
}



groundFungus

Quote
When i disconnect the 12v supply to the fan, the Uno still picks up a frequency of 50Hz from pin 2.
That sounds like pin 2 is floating and picking up noise from the environment.  It may be that the tach signal is an open collector (or drain) output.  I haven't been able to find a spec on that fan that shows the tach circuit so don't know.  You could try enabling the internal pullup on pin 2 to see if it helps to pull the tach signal line up.

MarkT

Well you are calling delay so that each call to pulseInLong starts at some arbitrary point, which won't help:

Try:
Code: [Select]

  pulseInLong (pin, LOW) ; // synchronize
  long high = pulseInLong(pin, HIGH);  // time high
  long low = pulseInLong(pin, LOW);  // time low
  Serial.print("High: ");
  Serial.println(high);
  Serial.print("Low: ");
  Serial.println(low);
 
  f=1.0/((high + low)*1e-6);
  Serial.print("Hz: ");
  Serial.println(f);
  delay(1000);

[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

jone886

That sounds like pin 2 is floating and picking up noise from the environment.  It may be that the tach signal is an open collector (or drain) output.  I haven't been able to find a spec on that fan that shows the tach circuit so don't know.  You could try enabling the internal pullup on pin 2 to see if it helps to pull the tach signal line up.
Thanks for you help. Please see my original post, i have added the spec from Noctua support. I followed the recommendation but no luck at all. Another issue i have got is when i connect the fan ground and arduino ground to the ground of 12v power, i get no measurements at all. As soon as i remove the arduino ground, i started to get measurements. Do you know what is the possible issue? thank you.

jone886

Well you are calling delay so that each call to pulseInLong starts at some arbitrary point, which won't help:

Try:
Code: [Select]

  pulseInLong (pin, LOW) ; // synchronize
  long high = pulseInLong(pin, HIGH);  // time high
  long low = pulseInLong(pin, LOW);  // time low
  Serial.print("High: ");
  Serial.println(high);
  Serial.print("Low: ");
  Serial.println(low);
 
  f=1.0/((high + low)*1e-6);
  Serial.print("Hz: ");
  Serial.println(f);
  delay(1000);


Hi MarkT, thanks very much for your help. Please see 2nd attachment of the 1st post for result. There is a big difference between the High time and Low time. Sometimes it seems very close, most of the time is not. Any idea?

MarkT

Hi MarkT, thanks very much for your help. Please see 2nd attachment of the 1st post for result. There is a big difference between the High time and Low time. Sometimes it seems very close, most of the time is not. Any idea?
Why would the old behaviour be interesting, I know its going to be wrong, what is the behaviour
after my fix?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

jone886

Why would the old behaviour be interesting, I know its going to be wrong, what is the behaviour
after my fix?
Hi Mark, this is the behaviour after your fix.   :(

MarkT

You mean you edited the original posting?  That's going to risk destroying the continuity of the thread's storyline
and confuse people.

In that case I suspect you have some form of contact bounce from the fan's hall switches (bit odd), but
you are going to have to deal with it by filtering out short pulses maybe?  The three calls to pulse in should
avoid any issues with starting timing half-way through a pulse or trough, so the numbers are likely to be
valid.   One caveat is whether there is noise/interference on the signal line, which could be consfusing things.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

jone886

You mean you edited the original posting?  That's going to risk destroying the continuity of the thread's storyline
and confuse people.

In that case I suspect you have some form of contact bounce from the fan's hall switches (bit odd), but
you are going to have to deal with it by filtering out short pulses maybe?  The three calls to pulse in should
avoid any issues with starting timing half-way through a pulse or trough, so the numbers are likely to be
valid.   One caveat is whether there is noise/interference on the signal line, which could be consfusing things.
Sorry guys, i couldn't see any option to upload attachments in reply. So i added to my original post.

Anyway, thanks for your advise. i will try to look into adding a filter.

Wawa

Did you enable the internal pull up resistor on the pin, as you have been told by groundFungus in post#1.

pinMode(pin, INPUT_PULLUP);

Without that you won't get any signal from the hall sensor of the fan.
Leo..

jone886

Did you enable the internal pull up resistor on the pin, as you have been told by groundFungus in post#1.

pinMode(pin, INPUT_PULLUP);

Without that you won't get any signal from the hall sensor of the fan.
Leo..
Hi Leo,

yes i did, but it doesn't make any different. very random hz, i guess i need to figure out a filter to suit. Is there anything you can recommend regarding filter? Thanks.

Wawa

Why do you think filtering is needed. Is your wiring crappy?
Show us.

Did you see the Fan RPM page on this site.
Leo..




jone886

Why do you think filtering is needed. Is your wiring crappy?
Show us.

Did you see the Fan RPM page on this site.
Leo..

Hi Wawa,

here is the circuit.

Wawa

Circuit seems ok, but I would remove that pull up resistor and use internal pull up.

Does the fan run without any logic connected to the speed control wire? (blue coming out of the heatshrink)
I think that needs a logic HIGH (5volt) for the fan to run. Or a 5volt PWM signal.
Leo..

Go Up