kopia lustrzana https://github.com/cyoung/stratux
Merge remote-tracking branch 'origin/master' into ahrs_dev_protocolfun
commit
5bb15527f4
|
@ -21,19 +21,16 @@ const (
|
||||||
defaultTempTarget = 50.
|
defaultTempTarget = 50.
|
||||||
hysteresis = float32(1.)
|
hysteresis = float32(1.)
|
||||||
|
|
||||||
/* This puts our PWM frequency at 19.2 MHz / 128 =
|
pwmClockDivisor = 100
|
||||||
/* 150kHz. Higher frequencies will reduce audible switching
|
|
||||||
/* noise but will be less efficient */
|
|
||||||
pwmClockDivisor = 128
|
|
||||||
|
|
||||||
/* Minimum duty cycle is the point below which the fan does
|
/* Minimum duty cycle is the point below which the fan does
|
||||||
/* not spin. This depends on both your fan and the switching
|
/* not spin. This depends on both your fan and the switching
|
||||||
/* transistor used. */
|
/* transistor used. */
|
||||||
defaultPwmDutyMin = 20
|
defaultPwmDutyMin = 1
|
||||||
pwmDutyMax = 256
|
pwmDutyMax = 10
|
||||||
|
|
||||||
// how often to update
|
// how often to update
|
||||||
delaySeconds = 2
|
delaySeconds = 30
|
||||||
|
|
||||||
// GPIO-1/BCM "18"/Pin 12 on a Raspberry PI 3
|
// GPIO-1/BCM "18"/Pin 12 on a Raspberry PI 3
|
||||||
defaultPin = 1
|
defaultPin = 1
|
||||||
|
@ -50,8 +47,16 @@ var stdlog, errlog *log.Logger
|
||||||
|
|
||||||
func fanControl(pwmDutyMin int, pin int, tempTarget float32) {
|
func fanControl(pwmDutyMin int, pin int, tempTarget float32) {
|
||||||
cPin := C.int(pin)
|
cPin := C.int(pin)
|
||||||
|
|
||||||
C.wiringPiSetup()
|
C.wiringPiSetup()
|
||||||
C.pwmSetMode(C.PWM_MODE_BAL)
|
|
||||||
|
// 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_MS)
|
||||||
C.pinMode(cPin, C.PWM_OUTPUT)
|
C.pinMode(cPin, C.PWM_OUTPUT)
|
||||||
C.pwmSetRange(pwmDutyMax)
|
C.pwmSetRange(pwmDutyMax)
|
||||||
C.pwmSetClock(pwmClockDivisor)
|
C.pwmSetClock(pwmClockDivisor)
|
||||||
|
@ -64,21 +69,9 @@ func fanControl(pwmDutyMin int, pin int, tempTarget float32) {
|
||||||
})
|
})
|
||||||
pwmDuty := 0
|
pwmDuty := 0
|
||||||
|
|
||||||
tempWhenRampStarted := float32(0.)
|
|
||||||
for {
|
for {
|
||||||
if temp > (tempTarget + hysteresis) {
|
if temp > (tempTarget + hysteresis) {
|
||||||
if tempWhenRampStarted < 1. {
|
|
||||||
tempWhenRampStarted = temp
|
|
||||||
}
|
|
||||||
pwmDuty = iMax(iMin(pwmDutyMax, pwmDuty+1), pwmDutyMin)
|
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) {
|
} else if temp < (tempTarget - hysteresis) {
|
||||||
pwmDuty = iMax(pwmDuty-1, 0)
|
pwmDuty = iMax(pwmDuty-1, 0)
|
||||||
if pwmDuty < pwmDutyMin {
|
if pwmDuty < pwmDutyMin {
|
||||||
|
|
Ładowanie…
Reference in New Issue