dan s
Posts: 132
Joined: Tue Feb 18, 2020 10:42 pm

An example python pwm fan cotroller

Mon Oct 11, 2021 2:34 am

I've been using it for a while now, so I threw it in a repo incase someone else might find it useful.
https://github.com/dans98/cm4-pwm-fan

The highlights :
You define a series of control points that represent a pwm temperature control curve like you would see in the bios of a typical desktop computer. The python script linearly interpolates the points, and adjusts the fan pwm duty cycle accordingly. The script also supports the following specialty features.
  • Auto on/off - The fan will not turn on until the cpu temperature rises above the lowest temperature control point in the fan curve. If the temperature falls below the lowest control point, the fan will automatically shut off.
  • Auto Max fan - If the cpu temperature goes above the highest control point temperature, the fan will automatically go to 100%. The fan will stay at 100% until the cpu temperature drops below the highest control point temperature.
Example fan curve :
Image

Example stress test results :
Image

BeauSlim
Posts: 140
Joined: Mon Jul 31, 2017 10:02 am

Re: An example python pwm fan cotroller

Thu Oct 14, 2021 12:15 am

Thanks!

Your timing is perfect. My waveshare -B board just arrived (to replace the -A) so I needed a different PWM control for Ubuntu 64 and your script works without modification.

The anti-hunting feature is much appreciated.

dan s
Posts: 132
Joined: Tue Feb 18, 2020 10:42 pm

Re: An example python pwm fan cotroller

Thu Oct 14, 2021 6:13 pm

BeauSlim wrote:
Thu Oct 14, 2021 12:15 am
The anti-hunting feature is much appreciated.
Thats was one of the hardest things to come up with.

I tried several methodologies to minimize the "noisy" temperature readings. I tried excluding readings base on standard deviation, mean, and average. I also tried various curve fitting methodologies to try and predict what the fan duty cycle should be.

However, nothing worked better than the fairly simple methodology of averaging multiple readings, and requiring a minimum delta to change the fan pwm setting.

I'm running a 30mm fan in my set-up so any change in speed if fairly noticeable. If you run a larger fan (generally quieter), the settings can all be relaxed.

I really with the waveshare baseboard supported 12v fans.

It also would have also been nice, if the hdmi and usb-c ports had both been vertical ports. That would have allowed them to have the Ethernet, usb 2.0, usb-c, and hdmi ports all along one edge. That would have made for a nice little desktop server set-up in my opinion.

Return to “Compute Module”