I have a pi4 with the "official" fan case and I would like to write my own fan control code. I have looked online for a datasheet for the fan but haven't found it yet. I see on the case fan page that it is controlled by "Pulse width modulation control via user-selectable GPIO pin." Does anyone know the PWM frequency is? Bonus points if anyone knows the duty cycle to RPM mapping.
-
1Had a hunt - got lost in kernel overlays and C programming (I rate myself very low skill on both). raspi-config sets config.txt for temperature and pin but github.com/raspberrypi/linux/blob/rpi-5.4.y/drivers/hwmon/… seems to take fan speed from dev_get_drvdata and convert to PWM I THINK. There may be something like a map in github.com/raspberrypi/linux/blob/rpi-5.4.y/arch/arm/boot/dts/… but no idea if data is the same... Sorry but may help if no one else has answer. Tempted to say - create your own and tweak through trail & error :-)– user115418Commented Dec 19, 2020 at 16:53
2 Answers
Ok I think I got the answer: 25kHz
I found this slide deck (download link) from ADDA (the manufacturer) that says the frequency is 25k. To verify this, I hooked up the official fan to a pi 3b+ I use for GPIO testing. I plugged the blue wire into GPIO 12 since the standard pin (GPIO 14) doesn't have the hardware PWM you need to exceed 7kHz. Then I used sysfs to enable PWM control and verified that I could fine-tune the fan speed by changing the duty cycle.
A couple more notes:
I still don't know the RPM profile of the fan. I am not really concerned about this but still curious in case anyone knows it.
It's interesting that the fan instructions have you use GPIO 14, which is incapable of PWM control other than duty cycles of 0% (off) and 100% (on). This seems to indicate that the fan is not really intended to be used with fine-tuned control, only to be turned on and off by the OS. Simply plugging the blue wire into GPIO 18 two pins over would have enabled this, and I confirmed you can fit the lead there in the official fan and official case, but someone clearly chose not to put that in the instructions, so I think anyone wanting to fine-tune their fan control is clearly going to be on their own!
-
-
Do you know how PWM works? You need the correct frequency for it to function properly.– mattexxCommented Dec 21, 2020 at 1:10