<div dir="ltr">Apparently one cannot control both pwm outputs simultaneously. When one of the pwm outputs was disabled, the service does work correctly after a reboot. The bcm2835 driver which is used by this project apparently silently fails! It sure would be nice if the applet logged this somewhere. This was a devil to find... There was an oblique reference to silent failing in the bcm2835 library documentation, which gave me a clue.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 19, 2021 at 5:05 PM Bruce Labitt <<a href="mailto:bdlabitt@gmail.com">bdlabitt@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I found a project on <a href="https://gist.github.com/alwynallan/1c13096c4cd675f38405702e89e0c536" target="_blank">https://gist.github.com/alwynallan/1c13096c4cd675f38405702e89e0c536</a> 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.<div><br></div><div>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.</div><div><br></div><div>The pi_fan_hwpwm.service is</div><div><font face="monospace">[Unit]<br>Description=Hardware PWM control for Raspberry Pi 4 Case Fan<br>After=syslog.target<br><br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/run<br>PIDFile=/run/pi_fan_hwpwm.pid<br>ExecStart=/usr/local/sbin/pi_fan_hwpwm<br>Restart=on-failure<br><br>[Install]<br>WantedBy=multi-user.target<br></font></div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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. </div><div><br></div><div>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. <br></div><div><br></div><div><br></div></div>
</blockquote></div>