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.Message
Re: [AVR-Chat] Monitoring 4 wire fans
2011-10-11 by David Kelly
Attachments
- No local attachments were found for this message.