Go Down

Topic: reading rpm signal from cpu fan (Read 28823 times) previous topic - next topic


Ok I finally got this working with the help of a friend. I have posted it on my site http://themakersworkbench.com/?q=node/350

Code: [Select]
//Code by Crenn from thebestcasescenario.com

//Varibles used for calculations
int NbTopsFan;
int Calc;
char counter;
char flag;
unsigned long time[2];

//The pin location of the sensor
int hallsensor = 2;

//Defines the structure for multiple fans and their dividers
typedef struct{
 char fantype;
 unsigned int fandiv;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 0;   //This is the variable used to select the fan and it's divider, set 1 for unipolar hall effect sensor
              //and 2 for bipolar hall effect sensor

//This is the function that the interupt calls
void rpm()
  if (counter == 0)
  if (counter == 100){
     cli();            //Disable interrupts

//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup()
pinMode(hallsensor, INPUT);
attachInterrupt(0, rpm, RISING);
void loop ()
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  Calc = (((60*100)/(time[1]-time[0]))/fanspace[fan].fandiv);
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" rpm\r\n"); //Prints " rpm" and a new line

Go Up