Hi!
I've found a code for reading RPM of a fan.
I see that in code, after the counter of RPM was reset, there are that snippet of code
sei()
delay()
cli()
Ok, it works either with or without sei/cli..so my question is: is necessary using those functions?
Here the test code.
void readFan() {
nTick = 0;
//sei();
delay(1000);
//cli();
Calc = (nTick* 60);
Serial.print (Calc);
}
void loop ()
{
for (int i = 255; i >= 80; i -= 10) {
//sei();
analogWrite(fanPin, i);
delay(1000); // Wait for stabilize RPM
readFan();
//cli();
}
Another question. I'm trying to read the RPM for some range of PWM value.
The actual code is working perfectly, but if inside readFan() I decomment sei/cli, the program stops and the loop doesn't continue (I hear the fan always the same speed).
Instead, if I decomment the sei/cli inside main "loop" routine it works..
I'm a bit confused about that..for reading the fan RPM and setting the PWM value, I should use those interrupt flag??
Ps:- sorry for my awful English..
Thanks a lot