Hello everybody, First of all I want to say that I am a newbie at arduino. I am working on a school project. The idea is simple: - 1 intel pc cooler 4 wires(PWM on pin 9), TACH to pin 2 (intrreupt 0) - 1 potentiometer (Signal on pin A0) - 1 arduino duemilanove
What i want to do is use the potentiometer to set the speed of the pc fan, used it as the setPoint to feed it to a PID, get the rpm of fan(code copied from rpm post :D ), feed the rpm to the pid, and calculate the output. So far with out the analogWrite function i get normal readings of the rpm: 1660 1650 rpm, when ai insert in the loop analogWrite(9,128), the rpm readings send mutate to HULK-like values 56000-7800 rpm: Here is ze code:
#include "TimerOne.h"
volatile byte rpmcount;
unsigned int rpm;
int value,pwm;
unsigned long timeold;
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, RISING);
//my code
pinMode(9,OUTPUT);
pinMode(A0,INPUT);
//end
//Timer1.initialize(500000);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
//Timer1.pwm(9,512,500000);
if (rpmcount >= 20) {
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm,DEC);
}
analogWrite(9,128);
}
Did something like this happen to someone else?