Dimming high current bulb using PWM and a SMPS - solved

Thread Starter

Budreaux

Joined Oct 3, 2012
18
OK, so a final tweak of the code, I set the pwm to 254 for 3 seconds at startup and then my warm up loop runs. Now, on startup, the SMPS drops for about half a second and then comes up. The rest of the program then runs as expected. It appears the smaller pulse width (which is the smallest I can implement) has dampened the effect enough to be usable. I'm wondering if changing the pwm frequency would help at all. Question is, do I go slower or faster. My guess is faster so the load appears for a shorter amount of time and this may fall outside the range of the SMPS over current protection circuit. Thoughts?
 

AlbertHall

Joined Jun 4, 2014
12,346
OK, so a final tweak of the code, I set the pwm to 254 for 3 seconds at startup and then my warm up loop runs. Now, on startup, the SMPS drops for about half a second and then comes up. The rest of the program then runs as expected. It appears the smaller pulse width (which is the smallest I can implement) has dampened the effect enough to be usable. I'm wondering if changing the pwm frequency would help at all. Question is, do I go slower or faster. My guess is faster so the load appears for a shorter amount of time and this may fall outside the range of the SMPS over current protection circuit. Thoughts?
Experiment will get you the answer to that. Do you have the extra capacitors fitted?
 

Thread Starter

Budreaux

Joined Oct 3, 2012
18
Albert, I did just that. I changed the internal frequency of the micro from 8MHz to 16MHz which changed the PWM frequency from 500Hz to 1kHz, no change in the behavior. If I try to increase the frequency any more, it will affect timer0 which will wreak havoc with the rest of my program.

Alec, I'm going to go out on a limb here and assume you are referring to my first schematic with regard to the resistor designations (those changed with my last schematic pic - sorry, this is from a circuit I was using for something else and just modified it for this purpose). In that case, it could be due to my misunderstanding of how to select the proper resistors. My thinking was to limit the current from the micro to below 20mA and limit the current to the gate of the mosfet, but I don't remember why now. I know you mentioned swapping the values of the two, but I'm not sure why (or, more to the point, I'd like to understand why).
 

Thread Starter

Budreaux

Joined Oct 3, 2012
18
OK, at last I have found the problem. The micro writes a 0 to all I/O ports at initialization. Even with the pull-up resistor, the transistor will be pulled low for a few micro seconds before it is pulled high. This means I should be using a PNP with a pull-down resistor to ensure the gate of the mosfet will stay off until the program starts. Thanks to everyone who was helping me with this.
 

Alec_t

Joined Sep 17, 2013
14,314
My thinking was to limit the current from the micro to below 20mA and limit the current to the gate of the mosfet, but I don't remember why now. I know you mentioned swapping the values of the two, but I'm not sure why (or, more to the point, I'd like to understand why).
When switching MOSFETs, they need to transition from on to off and vice versa as quickly as possible to minimise the heat generated in them. The gate behaves as a capacitor, so to charge/discharge that quickly the driving circuit resistance should be minimal. Hence R9 (post #15) could be reduced by at least an order of magnitude to speed up the gate capacitance charging.
A rule of thumb for using a BJT as a switch is to make the base current about a tenth of the collector current; hence the base resistor value would normally be many times the collector resistor value.
 

ronsimpson

Joined Oct 7, 2019
3,037
The MOSFET has a Gate pull up resistor to +24V. The MOSFET has a max G-S voltage of only 20V. Try moving the resistor to pull up to +12V. (the fan voltage).
Or you can add a G-S resistor to make a voltage divider. (5k minimum to 33k max)
 

Thread Starter

Budreaux

Joined Oct 3, 2012
18
So many responses to answer, where to begin.

The MOSFET has a Gate pull up resistor to +24V.
Ron, Ron, Ron......where were you last week buddy, lol. Of course, the resistor is pulling the gate high when Q1 is off. That's why its been acting erractically. I also read the datasheet wrong. It actually appears as though I can drive this mosfet directly from the micro. So I don't even have to mess with Q1. I will try that out and let you know what I get.

Depends upon the voltage connected to the PNP emitter.
It can't be higher than the micro supply voltage.
You are correct. Trying to substitute a PNP for the NPN and rerouting the circuit did not work for me at all.

Curious. Reading the datasheet, it seems the micro sets them as tristate on reset. Does the chip have a bootloader code (which might mess with the pins) or is it a bare chip?
Yes, it has a bootloader, but I may have just figured out the actual problem. We'll see with my next update.

When switching MOSFETs, they need to transition from on to off and vice versa as quickly as possible to minimise the heat generated in them. The gate behaves as a capacitor, so to charge/discharge that quickly the driving circuit resistance should be minimal.
Alec, thanks for the info. I will commit this to memory now.
 

Thread Starter

Budreaux

Joined Oct 3, 2012
18
OK, thanks to all who helped me with this. The circuit is now happy and working the way it should. Here is the final circuit and unless someone sees something glaringly wrong with it, it's what I will be going with.pwmCircuitFinal.jpg
 

ericgibbs

Joined Jan 29, 2010
18,849
hi Bud,
As there is a MCU on that PCB working alongside Power FET's , I will again draw your attention to increasing the decoupling cap values.
E
 

Thread Starter

Budreaux

Joined Oct 3, 2012
18
hi Bud,
As there is a MCU on that PCB working alongside Power FET's , I will again draw your attention to increasing the decoupling cap values.
E
Eric, thank you. Yes, I did make that change, I just copied the wrong schematic. Here is the one with the caps in place. pwmCircuitFinal2.jpg
 
Top