My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Formular  
The formular used to calculate fan speed
Featured
Updated Feb 4, 2010 by raimorad...@gmail.com

Introduction

The formular used by eeepc-fancontrol is very simple. Used variables are

  • $minSpeed (> 0 and < 100 and < $maxSpeed) for the minimum speed the fan should run,
  • $maxSpeed (> 0 and < 100 and > $minSpeed) for the maximum speed,
  • $normalTemp (> 0 and < $highTemp) for the temperature the fan should start spinning at $minSpeed,
  • $highTemp (> 0 and > $normalTemp) for the temperature the fan should spin at $maxSpeed

Details

Additional information: The fan speed value is 0 to 100. Those are percentages (wow!). The fan itself is PWM controlled.

ATTENTION: You need to set $minSpeed to at least 14. Everything under 14% is not enough to power the motor inside the fan. It will stop spinning. Version 0.12 implements routines to check if the fan still spins.

The daemon adjusts fan speed by translating the temperature + the variables linear to a fan speed. The speedPercentage per Celsius+$normalTemp is calculated this way:

$speedPercentage = $minSpeed+(($maxSpeed-$minSpeed)/($highTemp-$normalTemp)*($currentTemperature-$normalTemp))

This formular is quite simple but effective. This way fan really spins only if needed.

Applicable settings for the vars are (tested, usualy not harming)

$minSpeed = 14
$maxSpeed = 100
$normalTemp = 50
$highTemp = 60
Comment by msh.comp...@gmail.com, Jul 25, 2008

I have ported to C and most function works. Some features bot ported. I ould post here, if someone find it usefull.

Just copy text and paste to a source file example eee-fan.c and compile gcc -O2 eee-fan.c -o eee-fanctrl and run eee-fanctrl &

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

// Author Steve Kieu <kieusnz@yahoo.co.nz>
// Ported from the perl version, No warranty of any kind
// GPL licence

int interval	=	5;
/* Maximum/Minimum Fan Speed
 ATTENTION: $minSpeed MUST be higher than 14*/
int maxSpeed	=	100;
int minSpeed	=	0;

// Temperatures for when to set $maxSpeed / $minSpeed
int highTemp	=	60; //58;
int normalTemp 	=	52; //50;

int startSpeed	=	40;
int stopSpeed	=	14;

void checkFanRPM() {
	if(getFanRPM() < 10 && getFanSpeed() != 0) {
		printf("Fan stopped spinning. Speed raised to: %d\n", startSpeed);
		setFanSpeed(startSpeed);
		sleep(1);
	}
}

void setFanSpeed(int sp) {
	int speed = sp;
	if(speed > 0 && speed < stopSpeed) { 
	speed = 14 ;
	return ;}
	if(speed == getFanSpeed()) return;
	printf("Speed set to: %d\n", speed);
	char s[65];
	sprintf(s, "%d", speed);
	write_string_to_file("/proc/eee/fan_speed", s);
}

void terminateFancontrol() {
	FanOverride(0);
	printf( "Hardware Fan Control restored\n");
	printf("Shutting down...\n");
	exit(1);
}

int read_num_from_file(char *path, int pos) {
	printf ("Funct read_num_from_file with %s\n", path );
	FILE *f;
	f = fopen(path, "r");
	char test[80];
	int count = 0;
	if (pos !=1) {
	while (++count < pos) {
		fscanf(f, "%s", test);
	}
	}
	else {
		fscanf(f, "%s", test);
	}
	fclose(f);
	printf("number read: %d\n", atoi(test));
	return(atoi(test));
}

void write_string_to_file(char *path, char* s) {
	printf ("Funct write_string_to_file with %s, string %s\n", path, s );
	FILE *f;
	f = fopen(path, "w");
	fprintf(f, "%s", s);
	fclose(f);
}

int getFanSpeed() {
	return (read_num_from_file("/proc/eee/fan_speed", 1));
}

int getFanRPM() {
	return(read_num_from_file("/proc/eee/fan_rpm", 1) );
}

int getTemperature() {
	return (read_num_from_file("/proc/eee/temperature", 1));
}

void checkFanOverride() {
	int currentFanState = read_num_from_file("/proc/eee/fan_manual",1); 
	if(currentFanState == 0) FanOverride(1) ;
}

void FanOverride(int st) {
	int state = st;
	char s[65];
	sprintf(s, "%d", st);
	write_string_to_file("/proc/eee/fan_manual", s);
	printf("Fan Control Override triggered\n");
}

int main() {
int jump = (maxSpeed - minSpeed)/(highTemp - normalTemp);

while (1) {
	checkFanOverride();
	checkFanRPM();
	int temperature = getTemperature();
	if (temperature < normalTemp) { setFanSpeed(minSpeed); }
	else if(temperature > highTemp) { setFanSpeed(maxSpeed); }
	else { setFanSpeed(minSpeed+jump*(temperature-normalTemp));
	}
	sleep(interval);
}
}

Sign in to add a comment
Powered by Google Project Hosting