Driving MOSFET with PWM signal from 18F4550

Discussion in 'Embedded Systems and Microcontrollers' started by Vitesse, May 24, 2013.

  1. Vitesse

    Thread Starter New Member

    Feb 10, 2013
    5
    0
    Hi Guys,

    Stuck on a little problem (or several problems).

    I'm working on a project to PWM control a couple of PC fans from a PIC18F4550 and as there will be 4 fans wired in parallel I thought the best option would be to use a MOSFET rather than an NPN transistor due to the higher current requirements.

    So, I've used the attached circuit however It seems that I dont get full control of the fan speed, it seems to be achieving full speed with only about a 50% PWM duty cycle, now I wasnt sure if this was just due to the fan itself so i've tried a few different ones with the same result.

    Can someone please just have a glance over my circuit (attached) and see what they think and if there is something wrong, what I might be able to try to resolve the problem. The PWM frequency is 25KHz which should be well within the capabilities of the STP36NF I am using.

    Thanks
     
  2. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,015
    3,789
    When your CCPR2L register (on-duty period) is greater than PR2 (PWM Period) register, then you will always be on (No PWM control - just on).
     
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Your circuit is fine.

    The symptom is quite normal. PC fans have electronics built in, and don't need the full continuous 12v to get to full fan speed. So as you are finding the fans might be getting up to full speed long before your PWM gets to 100% PWM.

    The first thing I would do is put a cap across the fan and a resistor in series with one fan wire. Maybe a 470uF cap and a 100 ohm resistor. It depends on fan size and current.
     
  4. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    I think you should add push pull conf at mosfet gate to turn on/off mosfet fast b'coz discharging of gate capacitance take time...with using (directly) will get mosfet hot.
     
  5. Vitesse

    Thread Starter New Member

    Feb 10, 2013
    5
    0
    Hi GopherT, this doesnt appear to be the problem, as I have a LED (via suitable series resistor) connected to the PIC output, and brightness varies when setdcpwm1 is set to values ranging from 0-1023.

    Tried adding an electrolytic cap across the fan and this has had one good effect so far, reduced the noise the fan was producing and smoothed the speed out a little however still getting nothing resembling full control over it however I was hoping to avoid using a series resistor as this will be driving 4x120mm fans. Setting a value ranging from 270 - 520 gives Stall to 100% speed.

    This is the code im using for the PWM outputs (Hitech C)
    Code ( (Unknown Language)):
    1.  
    2. OpenPWM1(0xFF);
    3. OpenPWM2(0xFF);
    4. OpenTimer2(TIMER_INT_OFF & T2_PS_1_4 & T2_POST_1_1);
    5.  
    20MHz Xtal OSC


    no longer worrying about PWM frequency, just concentrating more on getting it to work then sort out the finer details later :)

    So far regarding temperatures the mosfet is absolutely stone-cold with no heatsink, this is only being breadboarded at the moment. Would a push-pull circuit result in better switching?

    Also a pecuiliarity, with an electrolytic cap across the fan, if i turn the 12V supply off (5v is separate) this is causing the PIC to reset, could this be that the cap on the 5V supply rail (100uF 16V) is too low a value? I also have a 100nf on each pic supply terminal bearing in mind this is powered by a bench PSU (12V and 5V) at present not a 7805/similar
     
    Last edited: May 24, 2013
  6. Vitesse

    Thread Starter New Member

    Feb 10, 2013
    5
    0
    Thanks for the input and advice earlier guys

    Another alternative I have been thinking about is there a way I can force the CCP module to go into 8-bit rather than 10-bit PWM even just as a temporary thing? This would certainly make debugging easier as sending a value in a single byte would reduce the chances of my poor coding also causing problems as at present I'm sending 2 bytes and performing maths to achieve what should be a fairly straightforward task and since this is just a fan speed control accuracy is not that important :)

    Thanks
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You need that series resistor if you are going to put a large electro across the fan wires (see my post above).

    Again, it's normal for the fan to need X volts to start turning. These fans have transistors and hall sensors etc inside, and have a minimum voltage before they start working.

    Re the 8bit PWM, that is very easy! All you do is just load your 8bit PWM byte into CCPRL as normal, but don't change the 2 LSB bits in CCP1CON.

    8bit PWM is probably plenty for a basic fan speed control (like you said). :)
     
  8. Vitesse

    Thread Starter New Member

    Feb 10, 2013
    5
    0
    Thanks RB, changing frequency and going 8-bit improved the control massively and managed to avoid the resistor and cap being needed :)

    And thanks to everyone who has provided me with guidance on this, much appreciated
     
Loading...