I'm working on a project, part of which requires getting the RPM of a PC fan with a tach output. The fan has an open drain output which goes low twice per revolution. And of course the pin has a pullup.
What I am doing is using an interrupt input (not a PCINT) detecting a falling edge of the tach. Another interrupt is setup in CTC mode and just increments a volatile uint16_t ("count"). That interrupt runs at 10000 per second (used for other stuff as well). I know that AVR interrupts are stopped while processing an interrupt, but my question is, are ALL interrupts stopped during that interval?
I ask because to get fan RPM, I plan to copy the count from the CTC interrupt, then zero it each time I get a fan tach interrupt. My concern is, will copying the count to another variable inside the tach ISR be ATOMIC?
I plan to do this:
busy = 1; // don't read var while it's being updated
value = count; // get a copy of count <--IS THIS ATOMIC???
count = 0; // reset count
busy = 0; // now "value" can be used
Note: "count" is 16 bit, hence my concern if the read is atomic.
Also note that I know the value gets LARGER as the fan gets slower... I simply left out code not relevant to my question.