I am trying to under stand the code for reading 3 wire PC fan RPM, should work on pin 2 and/or 3.
The code below works on int hallsensor = 2; // pin 2 location of the sensor Prints the same fan RPM in two spots.
When I change to int hallsensor = 3; // pin 3 location of the sensor , wont read RPM- It still reads pin 2.
I changed the code to int hallsensor = 11; // pin 11 location of the sensor, Should not work at all and it still reads pin 2.
Is it some part of the code or is it the Duemilanove that is not letting me change from pin 2 to pin 3?
Can someone point me to some reading/reference to this piece of code?
//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
Thank you, Steve
//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 13, 4, 5, 6, 7);
/*To disable interrupts:
cli(); // disable global interrupts
and to enable them:
sei(); // enable interrupts
*/
//Varibles used for calculations
int NbTopsFan;
int Calc;
//The pin location of the sensor
int hallsensor = 2;
typedef struct{ //Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv;
}fanspec;
//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
char fan = 1; //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++;
}
//This is the setup function where the LCD is initialised,
//and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT); //Sets RPM pin to input
lcd.begin(20, 4); //Set up the LCD's number of rows and columns
attachInterrupt(0, rpm, RISING);
}
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
lcd.setCursor(0, 3);
lcd.print ("Fan1:"); //Prints " Fan1:"
lcd.setCursor(5, 3);
lcd.print (Calc, DEC); //Prints the number calculated above
// NbTopsFan = 0; //Set NbTops to 0 ready for calculation
// Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
lcd.setCursor(10, 3);
lcd.print ("Fan2:"); //Prints " Fan2:"
lcd.setCursor(15, 3);
lcd.print (Calc, DEC); //Prints the number calculated above
}