Hi all,
First a code snippet;
analogWrite(fan_pin, 0); // fan full throttle
oldHallRpmTime = micros(); // store start time
attachInterrupt(0, hallInterrupt, RISING); // analog2 = interrupt 0 on mega
while (hallCount < hallcounter) { } // while we have not yet counted the desired hall interrupts, do nothing
detachInterrupt(0); // analog2 = interrupt 0 on mega
unsigned long TimeuS = micros(); // store stop time
analogWrite(fan_pin, reqSpeed); // fan back to setted pwm speed
This part of code gets executed once every couple of seconds.
What it does is;
Set a pwm-controlled pc-fan full speed (otherwise the hallsensor in the fan won't work)
Store time in microseconds. (i know it has a resolution of four microseconds -> reference)
Attach an interrupt to count hall-sensor ticks. (isr is just a 'hallCount++' nothing more)
When there are enough (on top of sketch #define hallcounter 4) hall interrupts counted
Detach the hall-sensor interrupt
Store end time in microseconds
Set the original desired speed.
After that the counts and time are used to calculate rotations per minute. That works fairly well when the program collects 20 or so hall interrupts. Doing so will speed up the fan abviously.
To limit the time spend at full throttle i've let the program count to 3 (this will be 1.5 turn of the fan)instead of 20 hall-interrupts. The problem starts. In this situation the rotations per minute are not correct anymore. They are about 10% too high.
Could this be that the time the program uses is not accurate enough? (multiples of 4 microseconds) or do the surrounding functions (attach- ,detach interrupt and maybe storing the time) take relative too long?
regards,
Jeroen