Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Monitoring 4 wire fans

Monitoring 4 wire fans

2011-10-11 by Philippe Habib

I have a bunch of 4 wire fans to monitor.  These are fans that take a PWM input for speed, and have a tach output in the form of a square wave with a frequency proportional to speed.  A stopped fan puts out a constant low.

At low speed, the period is about 80ms, at full speed, about 9ms.

The tachs are connected to general purpose I/O so I can't just set a counter going to determine frequency and check up every so often.

To monitor them my first thought was going to wait until the signal level changed (or 50ms) and then wait for the signal level to change again (or 50ms) and figure if it changed twice the fan is turning.  Worst case that would take me about 40ms, with an average wait of 20ms.

Next idea was to read the input and figure any high means the fan is turning, then if the fan is low, wait up to 50ms for a high before declaring the fan dead.  Worst case is still 40ms, but the average wait drops because I only need the first wait 1/2 the time.

I don't need to monitor them very often.  Once a minute is plenty.

What are some other ways I can monitor these things with minimal overhead?

Re: [AVR-Chat] Monitoring 4 wire fans

2011-10-11 by H. Carl Ott

On Mon, Oct 10, 2011 at 10:49 PM, Philippe Habib <phabib@well.com> wrote:

> **
>
>
> I have a bunch of 4 wire fans to monitor. These are fans that take a PWM
> input for speed, and have a tach output in the form of a square wave with a
> frequency proportional to speed. A stopped fan puts out a constant low.
>
> At low speed, the period is about 80ms, at full speed, about 9ms.
>
> The tachs are connected to general purpose I/O so I can't just set a
> counter going to determine frequency and check up every so often.
>
> To monitor them my first thought was going to wait until the signal level
> changed (or 50ms) and then wait for the signal level to change again (or
> 50ms) and figure if it changed twice the fan is turning. Worst case that
> would take me about 40ms, with an average wait of 20ms.
>
> Next idea was to read the input and figure any high means the fan is
> turning, then if the fan is low, wait up to 50ms for a high before declaring
> the fan dead. Worst case is still 40ms, but the average wait drops because I
> only need the first wait 1/2 the time.
>
> I don't need to monitor them very often. Once a minute is plenty.
>
> What are some other ways I can monitor these things with minimal overhead?
>  __._,
>

  You don't mention which AVR you want to use. It also appears that you
don't care about the speed, just the fact that the fan is spinning.

    Anyhow, I'd just use a simple pin change interrupt if it was available.
 Set a flag bit in the pin change ISR (or increment a counter) , test it in
your main code.


-carl


[Non-text portions of this message have been removed]

Re: Monitoring 4 wire fans

2011-10-11 by brianafuk

> What are some other ways I can monitor these things with minimal overhead?
>

Resistor and capacitor as a simple LPF feeding an IO pin?

Re: [AVR-Chat] Monitoring 4 wire fans

2011-10-11 by David Kelly

On Oct 11, 2011, at 6:26 AM, H. Carl Ott wrote:

>  You don't mention which AVR you want to use. It also appears that you
> don't care about the speed, just the fact that the fan is spinning.
> 
>    Anyhow, I'd just use a simple pin change interrupt if it was available.
> Set a flag bit in the pin change ISR (or increment a counter) , test it in
> your main code.

Yes, there is a good chance the Pin Change interrupt system is available for the I/O pin if one can not move it elsewhere.

Should also have a clock interrupt already running for general time keeping. I like to run about 10 ms on this clock. Then can create dozens of "software timers" for things effortlessly. In the clock interrupt routine:

	if( fan_timer )
		fan_timer--;

In the pin change interrupt:

	fan_timer = 6;		//	at least 50 ms, sometimes 60

Then anywhere you want to know if the fan is running just check to see if fan_timer == 0 or not.

Or you can effect your own pin change interrupt in the 10 ms timer by sampling the fan and if it doesn't change in 10 times through the interrupt then its pretty reasonable to guess its not running. Of course there is always the chance the fan is also running in a 10 ms period in exact sync. So, run your timer interrupt clock faster.

	static uint8_t fan_state;
	extern uint8_t fan_count;
	uint8_t fan_port;

	fan_tmp = PORT_fan & (1<<fan_bit);  // only read port once
	if( fan_state ^ fan_tmp ) {	// xor, something changed
		fan_count = 10;
	} else if( fan_count ) {
		fan_count--;
	}
	fan_state = fan_tmp;	//  save for next time through

--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.