0
\$\begingroup\$

I am trying to control a DC voltage using pulse width modulation (PWM) and an N-channel MOSFET. The way I have set up the circuit is as follows:

enter image description here

However, instead of the motor I have a 100K resistor, in parallel with a 100microfarad (25V) capacitor in order to smooth out the voltage. I am measuring the voltage across this resistor to check if it is being regulated or not:

enter image description here

I am powering the load from the same Arduino (for the time being. I will power it with an external battery once I get PWM working). I have the following code running on the Arduino:

int pwmPin = 3; // connected to the MOSFET's gate
int val = 128;  // set between 0 and 255

void setup() {
   pinMode(pwmPin, OUTPUT);
}

void loop() {
   analogWrite(pwmPin, val);
}

However no matter what I set the value to, I see the output voltage to be the same value of 4.99V instead of being proportional to the duty cycle. This changes as I get very close to 0 (when val=10, V_out = 4.33V and when val=0, V_out = 0V).

Why is this happening? Is the transistor not fast enough? Is the capacitor not big enough? What am I doing wrong? Below are the datasheets for the components:

Transistor (TO-220)

Diode

Sorry if the post has become wordy. I have been downvoted in the past for not including enough details with my post (because I wanted to be concise) and now I am being cautious.

Any help is much appreciated!

Edit: Please disregard the values on the diagram. I have wired my circuit as shown but for the values, as explained in my post I am using the Arduino to power the load. Meaning that the positive pin of the load is connected to Arduino's 5V and the black line in the diagram is connected to the ground of the Arduino. (I did not make the diagram myself and I was myself confused about the 0-60V+ and 0-60- notation, I'm assuming it means the 10K resistor was chosen such that such a range of values would not damage the circuit) I have also included the datasheet to the specific transistor I am using. Thank you for the answers so far.

\$\endgroup\$
  • 1
    \$\begingroup\$ Even after your edit, your load voltage inputs are mislabeled. You should have left the original 5-60v designation on one, and called the other ground or 0v. Instead, what you have said is "I will connect a supply of anywhere from 0 to 120 volts here" which does not appear to be what you mean at all. \$\endgroup\$ – Chris Stratton Mar 25 '18 at 23:55
  • 1
    \$\begingroup\$ in my opinion a simple circuit diagram would show more and does the analysis easier \$\endgroup\$ – HerrderElektronik Mar 27 '18 at 5:41
3
\$\begingroup\$

Of course you get 4.99V. Why wouldn't you? There is nothing that would cause the behavior you're expecting. What you're expecting is for the output to behave as if it had been filtered through a low pass filter, and actively discharged through said filter according to the PWM duty cycle, not simply charged. With a negligible load attached.

If all you have is a capacitor and small parallel resistor with the ground line being switched by the MOSFET, duty cycle will not have any effect on the voltage.

When the MOSFET turns on, the capacitor (having fairly low ESR) will charge as fast as it possibly can - much much faster than 100KΩ will discharge it. By my estimates, assuming the capacitor has an ESR of 1Ω (a bit on the high side but not unusual for a small aluminum electrolytic capacitor), even at 1/256th duty cycle, it will charge up to 4.99V in about 40ms.

Your setup is not a filter, but essentially a peak detector. It will always charge to a voltage that is the peak voltage it sees. Duty cycle will not change this voltage, just how long it takes to reach it (which at the lowest duty cycle is in about 1/25th of a second).

If you want the voltage to vary with duty cycle, you must:

  1. Use a low pass filter
  2. Charge and discharge the capacitor through that filter, with PWM on/off corresponding to charge/discharge of the capacitor.

The simplest low pass filter is a resistor in series with a capacitor. If we let the capacitor be passively charged by connecting it through a high value series resistor to +5V, then we can connect the MOSFET so that it will discharge the capacitor when the output pin is HIGH like so:

enter image description here

The 330Ω resistor is to limit the current from the power supply through the MOSFET. But that, along with the low pass filter formed by R1 and C1, should give you a voltage that more or less varies with duty cycle.

This is of course impractical for anything beyond simple 'analog out' type applications. You can't use this to vary the voltage for any meaningful load.

If you want something more like a variable output power supply, it cannot be done this way. That requires active regulation (since you will have a variable load) as well as using an inductor instead of the resistor (since any series resistor will dissipate far too much power while limiting the current), using a diode etc.

In other words, making a buck converter. But that's out of scope.

\$\endgroup\$
  • \$\begingroup\$ Thank you for the great explanation! \$\endgroup\$ – pooya13 Oct 28 '20 at 5:14
  • 1
    \$\begingroup\$ Thanks. I'm sorry it took...wow, over 2 and a half years to get an answer. I don't know why your question was downvoted either, it's a good question and understandable - PWM can vary volume, motor speed, LED brightness, and heat output, so why not voltage? Believe it or not, voltage isn't special or unique. You always need a low pass filter. But for those examples, the filters are non obvious. \$\endgroup\$ – metacollin Oct 28 '20 at 11:13
  • \$\begingroup\$ One way to view a low pass filter is as something that stores and releases energy but at a controlled rate. In the case of a motor, rotor inertia, the winding inductance, and back em, and even the load on the motor all serve as low pass filters. If you have an electric stove, the burners are usually controlled via PWM, but sometimes with a huge cycle time - 30 seconds or so. Cast iron cookware works great on these because its thermal mass acts as a low pass filter for the heat, while aluminum may be harder to keep a steady temperature. In the case of LEDs, the filter is our retina itself. \$\endgroup\$ – metacollin Oct 28 '20 at 11:23
-2
\$\begingroup\$

Your 100K resistor is not conductive enough to meaningfully discharge the capacitor during the gaps in the PWM waveform. In effect, it merely "holds the peak" of the applied voltage. If you used something like a flashlight bulb as a load, you might start to see a time average matching your expectation.

It's also a bit unclear if you are measuring across the capacitor, or between the always-high side of the capacitor and the unswitched ground.

You also seem to have mis-labeled the lower side of the load power supply - that should probably be "ground" not "5-60v -"

Finally the TIP120 is a Darlington transistor, effectively a dual-stage Junction Transistor, not a MOSFET as claimed in your title.

\$\endgroup\$
  • \$\begingroup\$ or "5-60v -" meaning Supply return (-) at source defined as 0V or Gnd... just adding clarification. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 25 '18 at 23:26
  • 1
    \$\begingroup\$ No. As drawn the diagram implies 10-120v across the motor. This is almost certainly not what the user means, the point here was that their drawing is in error in this regard. \$\endgroup\$ – Chris Stratton Mar 25 '18 at 23:40
  • \$\begingroup\$ OK but I read it as (V+ and V-) terminals on supply set to x -xx V where V- is obviously connected to GND and not -5 to -60V \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 25 '18 at 23:43
  • 2
    \$\begingroup\$ That was probably the intent, yes, but labelling that way is an error, as such labelling would mean twice that voltage. The point was explaining to the user that they have made an error in labeling their drawing. You can have a V+ terminal and a V- terminal, but if you put numbers on both of them, the potential is either the difference of those numbers, or else your terminals are incorrectly labeled. \$\endgroup\$ – Chris Stratton Mar 25 '18 at 23:44
-2
\$\begingroup\$

This is not an answer but if you understand impedance ratios or a switched voltage divider, this should lead you think about your results and understand why.

Instead of 100K Resistor try an 8W bulb or a small motor or 10 Ohm 1W resistor.

Using semiconductors as switches for PWM:


Average Resistance = ESR/d for duty cycle d and ESR means RdsOn or Rce for MSOFETs or BJT's the incremental resistance. But Dual transistors have the effect of 1 then 2 PN junctions add to the ESR. (more on this later .. see graph)

A Mosfet has RdsOn which requires usually >=2.5x Vgs(th) to switch on the internal resistance.

A BJT requires Ib = 10% of Ic to achieve the Vce(sat) spec. A dual BJT (Darlington) requires Ib = 0.4% of Ic for Vce(sat) up to 3A and 20mA@5A

This implies to efficiently saturate the switch you need to overdrive it implying the current gain is reduced to 10% of hFE.

Although the Ic is somewhat nonlinear, there are linear sections of collector-emitter, Rce or Effective Series Resistance , ESR that are useful to remember.

ESR = Rce = ΔVce/ΔIc between two points on the curve.
Extrapolate the tangent to read the slope.

TIP 120 , for Ic < 1A Ic = 0.7V+0.1*Ic (Rce=0.1 Ohm)

If the Motor coil DC resistance or DCR is >> 0.1 Ohm and this V+/(Rce+DCR) is less than 3A then it should work with the understanding the Vce =2V @3A is significant.

So the supply may need to be 2V higher than the motor rated voltage for max RPM. This is not the case when using a very low RdsOn part which may cost a bit more. RdsOn << 100 mOhm is very common in SMD parts which dissipate less heat and easier ('C/W) in a smaller case size. enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ lame users without comments (-1) \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 25 '18 at 23:01
  • 1
    \$\begingroup\$ Hi Tony, I didn't downvote you, but I knew this answer was written by you as soon as I read the first few lines. That should tell you something. In this case I think that a highly technical answer isn't appropriate for this beginner-level question. He's not trying to analytically determine the voltage to the nth decimal place, he's just trying to understand basics of what is happening. \$\endgroup\$ – Drew Oct 28 '20 at 6:31
  • \$\begingroup\$ I rarely use more than 2 sigfigs. As I stated this is n extended comment not for newbie but to raise the intel well above the troll -1. The professiona lway to look at this problem is in my 1st statement by impedance ratios \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Oct 28 '20 at 6:33
  • 1
    \$\begingroup\$ To put it another way, It's like if somebody asked why their LED wasn't lighting, and you could see in the picture that the battery is backwards. You wouldn't answer with a long post about complex impedance's and battery chemistry. \$\endgroup\$ – Drew Oct 28 '20 at 6:38
  • \$\begingroup\$ Point taken, although impedance ratios are still the point and the accepted answer may have overlooked the intention of the capacitor to represent a surge load which doesn't work from a voltage switched source that opens rather one needs a current source to a cap or a voltage source to an inductive motor to perform integration. I'll delete it \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Oct 28 '20 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.