Posts: 6
Joined: Tue May 23, 2017 9:52 am

PWM DC 12v 4-pin fan woes - Fixed

Tue May 23, 2017 10:06 am

Hi Guys
Pretty new to this and a terrible coder!

I am attempting to control multiple PWM 12v DC Fans ( ... GA38_E.pdf)

I have PWM fan control working to a degree via wiringpi on Pin18 but I cannot get a stable control from 0-100% duty cycle or on more than one fan at a time. It is very strange.
I am familiar with wiring these fans to a motherboard, in this case a single motherboard fan header can control multiple fans simply by connecting all of the fan PWM control wires to the same PWM header. It seems with the Pi, the drive strength of the PWM is not enough (ie too low voltage?)

Code: Select all

import wiringpi  
import time

print "hello"


wiringpi.pwmSetMode(1) # PWM_MODE_MS = 1

print "setupgpIO"

wiringpi.pinMode(18, 2)      # pwm only works on GPIO port 18

print "pwm mode set"

wiringpi.pullUpDnControl(18, 2) # 0=None; 1=Pull Down; 2=Pull Up

print "Pwm pull up active"

wiringpi.pwmSetClock(4)  # this parameters correspond to 25kHz

print "pwm clock set"

print "pwm range set"

wiringpi.pwmWrite(18, 76) # minimum RPM

print "Min RPM"

wiringpi.pwmWrite(18, 80)   # mid RPM

print "Mid 1 RPM"

wiringpi.pwmWrite(18, 90)   # mid RPM

print "Mid 2 RPM"

wiringpi.pwmWrite(18, 100)   # mid RPM

print "Mid 3 RPM"

wiringpi.pwmWrite(18, 110)   # mid RPM

print "Mid 4 RPM"

wiringpi.pwmWrite(18, 120)   # mid RPM

print "High RPM"

wiringpi.pwmWrite(18, 128)  # maximum RPM

print "Max RPM"

wiringpi.pwmWrite(18, 0)
wiringpi.pinMode(18, 0)
In my code, I cannot enter a lower value than 70 to have any effect on the fan speed, so the fan does not drop to very low duty cycles. I think perhaps the frequency is not 25Khz as it should be but have no scope to detect, or the voltage is not high enough - this spec seems to suggest 5v is needed. ... M_Spec.pdf page 11

It is also difficult to monitor the fan, I don't understand the code needed to take input from the RPM signal wire, if anyone can help there.

Do you guys think I have a hardware or a software problem? Should I bite the bullet and get a I2C PWM chip? This is a commercial project.

I also tried basic RPi GPIO with no luck.
Last edited by markodude on Tue May 23, 2017 12:32 pm, edited 1 time in total.

Posts: 6
Joined: Tue May 23, 2017 9:52 am

Re: PWM woes

Tue May 23, 2017 12:30 pm

Hi All,
Seems I got it to work - on both one, and multiple fans using the same PWM signal feed.
The missing link was a "common ground". I connected one of the RPi ground pins to the fan ground, and everything works as expected. Full control from 0-128 on duty cycle using the above script.
This is very good as it means no additional hardware is needed.
Next step is to implement RPM monitoring!

Return to “Beginners”