Pages: 1 2 [3]   Go Down
Author Topic: reading rpm signal from cpu fan  (Read 8182 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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;
}fanspec;

//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)
      time[0]=millis();
   if (counter == 100){
      time[1]=millis();
      flag=1;
      cli();            //Disable interrupts
   }
}

//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup()
{
 pinMode(hallsensor, INPUT);
 Serial.begin(9600);
 attachInterrupt(0, rpm, RISING);
}
void loop ()
{
   NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
   sei();            //Enables interrupts
   while(flag==0);
   flag=0;
   counter=0;
   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
}
Logged

Pages: 1 2 [3]   Go Up
Jump to: