View Single Post
Unread 07-30-2007, 12:52 PM   #7
Brians256
Pro/Staff
 
Brians256's Avatar
 
Join Date: Oct 2001
Location: Klamath Falls, OR
Posts: 1,439
Default Re: Q. Making a FAN controller

OK, if you want this to work for any and all rigs it becomes more complicated.

My suggestion is to have a tweaked parameter on the microcontroller that is derived for each system: calibration. Basically, you want the water temperature to be at or below a certain point.

Have a default value on the microcontroller for that water temperature and then feed an updated value to it from the computer when it boots. I assume your RS-232 interface to the microcontroller will be two way, right?

Also, counting pulses using the interrupt pin is ... messy. If your max frequency is X Hz, then sampling at 2X Hz is sufficient to reconstruct the state transitions and count. So, if you have something like a 50Khz timer interrupt, the code below will work well for fans that go up to 25,000 rpm.

Code:
static int LastFanValue = 0;
static int FanPulses = 0;
static int TicksSinceEvalRpm = 0;
static int CurFanRpm = 0;
#define TICKS_PER_RPM_EVAL 50000
#define RPM_EVALS_PER_MINUTE 60

void TimerTick()
{
    TicksSinceEvalRpm++;

    int iCurVal = GetFanValue_Register() & MAX_FAN_VALUE;
    if (iCurVal != LastFanValue)
    {
        FanPulses++;
        LastFanValue = iCurVal;
    }

    if (TicksSinceEvalRpm >= TICKS_PER_RPM_EVAL)
    {
        CurFanRpm = (FanPulses * RPM_EVALS_PER_MINUTE) / 2;
        FanPulses = 0;
        TicksSinceEvalRpm = 0;
    }


     AdjustFanSpeedFromTemp();  
}

void AdjustFanSpeedFromTemp()
{
      if (TicksSinceEvalRpm == 0)
     {
        // Adjust voltage for radiator fan
     }
}
Brians256 is offline   Reply With Quote