RPI HW PWM fan control
Bruce Labitt
bdlabitt at gmail.com
Fri Mar 19 17:05:12 EDT 2021
I found a project on
https://gist.github.com/alwynallan/1c13096c4cd675f38405702e89e0c536 for a
hardware controlled pwm fan for the RPI4. This should have low resource
usage, as compared to software controlled pwm. I don't have a Noctua type
pwm fan, but I made a simple circuit with a resistor, a transistor and a
flyback diode to drive a brushless DC motor from the GPIO pin. The
circuit, cobbled together on some perf board, works great.
This project works, but doesn't. By that I mean, if one makes and installs
the program along with a systemd service it works. However, the fan
control does not survive a reboot. More accurately, the service is
relaunched after boot - I can see it with # systemctl | grep pi_fan_hwpwm,
but the actual pin is not being controlled. The SW thinks it is
controlling the pwm pin output, but there is NO physical control of the
pin. As the core temp gets hotter and hotter the PWM duty factor
increases, as designed, but no signal is at the GPIO#18 pin.
The pi_fan_hwpwm.service is
[Unit]
Description=Hardware PWM control for Raspberry Pi 4 Case Fan
After=syslog.target
[Service]
Type=simple
User=root
WorkingDirectory=/run
PIDFile=/run/pi_fan_hwpwm.pid
ExecStart=/usr/local/sbin/pi_fan_hwpwm
Restart=on-failure
[Install]
WantedBy=multi-user.target
Multi-user.target.wants has pi_fan_hwpwm.service in its directory. The
service does start. However the actual control of the pin is somehow being
prevented. Even if I stop and start the service, the pin is not controlled.
I've turned off i2c, spi and audio in /boot/config.txt There's some
"mumbling" about doing things like this, both in the source of
pi_fan_hwpwm.c and in the header of bcm2835.h.
This project includes bcm2835.h to control the pwm. If I use the example
file found in bcm2835-1.68/examples/pwm/pwm.c and compile it, it controls
the fan. If I then stop and start the fan service (after running ./pwm
once) the fan pwm service now controls the fan physically. Comparing the
code in pwm.c and pi_fan_hwpwm.c reveals similar structure and
initialization. Have to say, this has been perplexing.
Besides giving up, which I have seriously considered, anyone got any
suggestions to make this work? Was hoping to use the HW controlled fan on
my RPI4 NAS.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/pipermail/gnhlug-discuss/attachments/20210319/75dad4d9/attachment.html
More information about the gnhlug-discuss
mailing list