#!/usr/bin/perl -w # A script to measure fan response to PWM at different frequencies # Copyright 2006-2007 Jean Delvare # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use vars qw($hwmon_dev $fan_file $pwm_file $freq_file @freqs $output_file); use strict; use constant SLEEP => 4; @freqs = (160000, 40000, 10000, 2000, 700, 500, 300, 100, 60, 30); $hwmon_dev = "/sys/class/hwmon/hwmon1/device"; $fan_file = "fan1_input"; $pwm_file = "pwm1"; $freq_file = "pwm1_freq"; $output_file = "/tmp/pwm_response.csv"; sub read_value($) { my $filename = shift; my $value; open(local *FILE, $filename); $value = ; close(FILE); chomp $value; return $value; } open(CSV, ">$output_file") or die; # Print header for (my $pwm = 248; $pwm; $pwm -= 8) { print CSV ";$pwm"; } print CSV "\n"; foreach my $freq (@freqs) { system("echo $freq > $hwmon_dev/$freq_file"); sleep(1); print "freq = $freq\n"; print CSV ($freq >= 1000 ? ($freq/1000)." kHz" : $freq." Hz"); for (my $pwm = 248; $pwm; $pwm -= 8) { system("echo $pwm > $hwmon_dev/$pwm_file"); sleep(SLEEP); my $fan1 = read_value("$hwmon_dev/$fan_file"); sleep(1); my $fan2 = read_value("$hwmon_dev/$fan_file"); sleep(1); my $fan3 = read_value("$hwmon_dev/$fan_file"); print CSV ";".int(($fan1+$fan2+$fan3)/3); } print CSV "\n"; system("echo 255 > $hwmon_dev/$pwm_file"); } close(CSV); system("echo 255 > $hwmon_dev/$pwm_file");