Funny readings when trying to read PWM fan RPM
i'm working on project test pc cooling fans - both 3-pin non pwm type , 4-pin pwm type. adjust 3-pin types via voltage , 4-pin via pwm obviously. display fan rpm, pwm% , voltage on lcd. works (still need add voltage part of code) 3-pin fans on pwm fans rpm reads way high (like 9k+ rpm) if pwm 0 or 100. pwm fans i've found work correctly stock intel cpu heat sink fans. read correctly no matter pwm setting. thoughts causing it?
here's code far (still need add voltage reading portion of it):
here's code far (still need add voltage reading portion of it):
code: [select]
// code pc fan testing unit
// lyon - http://www.computersandcircuits.com
#include <liquidcrystal.h>
liquidcrystal lcd(4, 5, 6, 7, 8, 9);
volatile int nbtopsfan;
int calc;
const int fan1 = 2;
const int potpin = a0;
const int pwmpin = 10;
const int voltpin = a2;
int fanpwm;
int val;
int pwm;
typedef struct{
char fantype;
unsigned int fandiv;
}fanspec;
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
char fan = 1;
void rpm ()
{
nbtopsfan++;
}
void setup() {
pinmode(fan1, input);
pinmode(potpin, input);
pinmode(voltpin, input);
attachinterrupt(0, rpm, rising);
lcd.begin(16, 2);
lcd.setcursor(0, 0);
lcd.print(" computers , ");
lcd.setcursor(0, 1);
lcd.print(" circuits ");
delay(2000);
lcd.clear();
lcd.setcursor(0, 0);
lcd.print(" computer fan ");
lcd.setcursor(0, 1);
lcd.print(" testing unit ");
delay(2000);
lcd.clear();
}
void loop() {
nbtopsfan = 0;
sei();
delay (1000);
cli();
calc = ((nbtopsfan * 60)/fanspace[fan].fandiv);
lcd.setcursor(0, 0);
lcd.print ("rpm");
lcd.setcursor(5, 0);
lcd.print ("pwm%");
lcd.setcursor(12, 0);
lcd.print ("volt");
lcd.setcursor(0, 1);
if (calc < 1000) lcd.print (' ');
if (calc < 100) lcd.print (' ');
if (calc < 10) lcd.print (' ');
lcd.print (calc);
lcd.setcursor(4, 1);
lcd.print (" ");
pwm = analogread(0);
fanpwm = map(pwm, 0, 1023, 0, 255);
analogwrite(pwmpin, fanpwm);
val = map(fanpwm, 0, 255, 0, 100);
lcd.setcursor(5, 1);
if (val < 100) lcd.print (' ');
if (val < 10) lcd.print (' ');
lcd.print(val);
}
code: [select]
sei();
delay (1000);
cli();
wrong!
you should using millis() determine when suitable interval has passed, , compute rpm. should not disabling interrupts.
Arduino Forum > Using Arduino > Programming Questions > Funny readings when trying to read PWM fan RPM
arduino
Comments
Post a Comment