|
Georg C. Kaindl wrote: Why not something like this?hi, int minTemp 50; //min temperature the fan can cool too int maxTemp 60; //the max temperate when the fan turns on 100% int tempStep = 5; //The temperature difference required for the fan to increase or //decrease speed int currentStep = minTemp; //currentStep starts out at minTemp or fan speed 0% //If the current temperature is atleast a step below the currentStep, decrease the //currentStep by one which slows the fan speed down one. If the current temperature //is greater then the currentStep then set the currentStep to the newStep. void setCurrentStep(int currentTemp) { int step = currentTemp / tempStep * tempStep; //force the current temp to fall on a step if(step < currentStep - tempStep) { currentStep--; } else if(step > currentStep) { if(step > maxTemp) step = maxTemp; //so it doesn't try to run the fan at 150% currentStep = step; //so it can jump multiple steps per call } } //set the current fan speed based on the current step. min = 0% max = 100% //and the fan speed scales linearly with the temperature. Increasing a certain //percentage for each step above minTemp double getFanSpeed() { return (currentStep - minTemp) / (maxTemp - minTemp); } So in this example the fan runs at 0% at [50-55) 50% at [55-60) 100% at [60-60+) When the temp becomes 55 or more, the fan speed becomes 50% Inorder for the fan to slow down from 50% the temperature must go below 50. Likewise when the temp becomes 60 the fan speed becomes 100% Inorder for the fan to slow down from 100% the temperature must go below 55. You can make the fan speed changes less severe by changing the tempStep value. But at a certain point you can set the value so low that the fan can start to undergo hysteresis. Also when the fan does get to that point the changes in the fan speed will be small. This is also mitigated by the example code using ints, which means the minimum step is 1 degree. Also if the fan can't cool the computer below minTemp it won't turn off. I didn't compile or test this code. I didn't look at the therm_adt7467 code either. Hope that makes sense and solves the problem. Mike Power |