From 4c854999bb66db369b279d576edad44936af6807 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 24 May 2017 13:24:46 -0400 Subject: [PATCH 1/3] Reduce number of fan modes to 10 from 256. Add five second run-up at startup. #599, #595, #593. --- main/fancontrol.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main/fancontrol.go b/main/fancontrol.go index 58b552f2..8b210e4e 100644 --- a/main/fancontrol.go +++ b/main/fancontrol.go @@ -21,19 +21,16 @@ const ( defaultTempTarget = 50. hysteresis = float32(1.) - /* This puts our PWM frequency at 19.2 MHz / 128 = - /* 150kHz. Higher frequencies will reduce audible switching - /* noise but will be less efficient */ - pwmClockDivisor = 128 + pwmClockDivisor = 100 /* Minimum duty cycle is the point below which the fan does /* not spin. This depends on both your fan and the switching /* transistor used. */ - defaultPwmDutyMin = 20 - pwmDutyMax = 256 + defaultPwmDutyMin = 1 + pwmDutyMax = 10 // how often to update - delaySeconds = 2 + delaySeconds = 30 // GPIO-1/BCM "18"/Pin 12 on a Raspberry PI 3 defaultPin = 1 @@ -50,7 +47,15 @@ var stdlog, errlog *log.Logger func fanControl(pwmDutyMin int, pin int, tempTarget float32) { cPin := C.int(pin) + C.wiringPiSetup() + + // Power on "test". Allows the user to verify that their fan is working. + C.pinMode(cPin, C.OUTPUT) + C.digitalWrite(cPin, C.HIGH) + time.Sleep(5 * time.Second) + C.digitalWrite(cPin, C.LOW) + C.pwmSetMode(C.PWM_MODE_BAL) C.pinMode(cPin, C.PWM_OUTPUT) C.pwmSetRange(pwmDutyMax) From daee7316f5f9e8efa12e1b29b08172fadb58501c Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 24 May 2017 13:25:52 -0400 Subject: [PATCH 2/3] Switch from "BAL" mode to "MS" PWM modes. #599, #595, #593. --- main/fancontrol.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/fancontrol.go b/main/fancontrol.go index 8b210e4e..4172e7b1 100644 --- a/main/fancontrol.go +++ b/main/fancontrol.go @@ -56,7 +56,7 @@ func fanControl(pwmDutyMin int, pin int, tempTarget float32) { time.Sleep(5 * time.Second) C.digitalWrite(cPin, C.LOW) - C.pwmSetMode(C.PWM_MODE_BAL) + C.pwmSetMode(C.PWM_MODE_MS) C.pinMode(cPin, C.PWM_OUTPUT) C.pwmSetRange(pwmDutyMax) C.pwmSetClock(pwmClockDivisor) From c3e4d613ca209f054e00ad4d43a7e7ca1e9c9e83 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 24 May 2017 21:42:11 -0400 Subject: [PATCH 3/3] Remove full speed defaults. #599, #595, #593. --- main/fancontrol.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/main/fancontrol.go b/main/fancontrol.go index 4172e7b1..00c65ee0 100644 --- a/main/fancontrol.go +++ b/main/fancontrol.go @@ -69,21 +69,9 @@ func fanControl(pwmDutyMin int, pin int, tempTarget float32) { }) pwmDuty := 0 - tempWhenRampStarted := float32(0.) for { if temp > (tempTarget + hysteresis) { - if tempWhenRampStarted < 1. { - tempWhenRampStarted = temp - } pwmDuty = iMax(iMin(pwmDutyMax, pwmDuty+1), pwmDutyMin) - if pwmDuty == pwmDutyMax { - // At the maximum duty cycle currently. - // Has the temperature increased "substantially" since the ramp-up started? - if temp > (tempWhenRampStarted + hysteresis) { - // Give up. The fan does not like the PWM control. - break - } - } } else if temp < (tempTarget - hysteresis) { pwmDuty = iMax(pwmDuty-1, 0) if pwmDuty < pwmDutyMin {