PWM in lieu of a current limiting resistor

All,

I'm curious what you think about using PWM to current-limit a lone LED instead of using a resistor. I'm not particularly a noob at Arduino. I tried running the Fade example sketch on a non-current-limited LED, and noticed that the LED really starts to dim at closer to analog write(100)--not 255. I'm thinking at that point the parasitic RC takes over and more-or-less protects the circuitry. The point is to shrink and simplify the circuitry, at the small price of giving up a little reliability. But I want to keep it down to a SMALL price; particularly for the Arduino board itself. Replacing the LED is no big deal (and I think it can take more than 40mA anyway).

All that being said, what do you think? If I never drive my LED's with more than analog write(100), do you think I can keep getting away with not putting in the resistor?

It will not work, do not even think about it. The peak current exceeds what the arduino can supply without damaging it.

driving an LED with PWM will lower the average current if you look at long enough of a time interval. However the peak current is what will kill either the LED or the pin on the Arduino.

This question must have been answered a hundred times by Grumpy Mike alone. My kudos you your patience Mike :wink:

Except it lowers the peak current, too. There is parasitic RC on the line. I could stick a cap on the line, and it would have the same effect so long as I was always PWMing. The pins are rated for 40mA continuous. At less than 50% duty cycle, the limit has got to be higher (we know how engineering specs and the true limits can be two different things). I don't care about the LEDs much, but if there are electromigration or dielectric problems on the pins themselves with the current spikes, I do care about that.

If there are other threads where people have oscilloscoped it and stuff, I will be glad to take a look. I can run on a coin cell battery and a cheap $2 cloned pro mini and it certainly does "work", but I was curious what else others have found out.

mapleleafs:
At less than 50% duty cycle, the limit has got to be higher (we know how engineering specs and the true limits can be two different things).

And others have often suggested just that, contrary to Mike's wisdom.

Don't forget however, the power law. P = I2R. Remember that the output devices in the chip are essentially resistive (look at their V:I curves). That means that passing double the current for half the time will double the power dissipation in the switching device. This also applies to the LEDs in respect of their ESR.

Except it lowers the peak current, too.

Total rubbish it does not.

I could stick a cap on the line, and it would have the same effect so long as I was always PWMing.

Wrong again, the capacitor looks like a short circuit to ground to the pin and so is even worse than an LED sitting at some forward Vref.

The pins are rated for 40mA continuous.

No they are not the 40mA is a stress rating.

At less than 50% duty cycle, the limit has got to be higher

Quite simply a total misunderstanding of electronics as a subject.

I don't care about the LEDs much,

You utter b******

but if there are electromigration or dielectric problems on the pins themselves with the current spikes, I do care about that.

Yes there are it is not just a power / heat issue.

If there are other threads

http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

I can run on a coin cell battery and a cheap $2 cloned pro mini and it certainly does "work",

Do not confuse "currently not broken" with "work".

mapleleafs:
Except it lowers the peak current, too. There is parasitic RC on the line. I could stick a cap on the line, and it would have the same effect so long as I was always PWMing. The pins are rated for 40mA continuous. At less than 50% duty cycle, the limit has got to be higher (we know how engineering specs and the true limits can be two different things). I don't care about the LEDs much, but if there are electromigration or dielectric problems on the pins themselves with the current spikes, I do care about that.

If there are other threads where people have oscilloscoped it and stuff, I will be glad to take a look. I can run on a coin cell battery and a cheap $2 cloned pro mini and it certainly does "work", but I was curious what else others have found out.

You came and asked what we think. We answered!
You can of course believe yourself and others. I tend to do thorough research not only on the subject but also on the folks that provide recommendations. In Mike's case that research leads me to believe he has 25+ of professional experience in designing/engineering electronics.

The fact that an LED does not start visually to dim at 255 but rather at 100 has absolutely nothing to do with parasitic RC but with how the human eye responds to changes in brightness.

1 Like

Why on earth are you wanting to omit a component costing a few pence/cents, when you risk damaging your Arduino costing more than €20/£25/$30?

Paul__B:
And others have often suggested just that, contrary to Mike's wisdom.

Don't forget however, the power law. P = I2R. Remember that the output devices in the chip are essentially resistive (look at their V:I curves). That means that passing double the current for half the time will double the power dissipation in the switching device. This also applies to the LEDs in respect of their ESR.

"P = I2R"
isn't that only when the component follows ohm's law?
for a led only a small voltage increase is needed to double the current, so then doing that at 50% duty cycle should only result in a minor increase in power, not doubling it. So i think his idea isn't that bad to be honest.
trying to do the same on something following ohm's law would be a terrible idea :).

So i think his idea isn't that bad to be honest.

No it is bad, very bad. It is not only power considerations that make it a bad idea.

trying to do the same on something following ohm's law would be a terrible idea

I think you are getting confused here, with what ohms law actually is.

Grumpy_Mike:
No it is bad, very bad. It is not only power considerations that make it a bad idea.
I think you are getting confused here, with what ohms law actually is.

you know what i mean :p. when varying the voltage it doesn't nicely follow ohms law like a resistor would.
What other effects would be bad in this case? i would expect not exceeding the power of the max rating (with fast enough pulses) to be safe since 40mA at 50% duty cycle would stress the circuit just as much as 20mA continuously (at the same voltage).
Which properties/effects come in play here that makes this not true?

since 40mA at 50% duty cycle would stress the circuit just as much as 20mA continuously (at the same voltage).

That is simply not true, I fail to understand what makes you think it is true. It shows that you have little understanding of what stressing a component means.

you know what i mean :p. when varying the voltage it doesn't nicely follow ohms law like a resistor would.

What makes you think that this affects anything? What is important is the power dissipation at any instance. This has nothing to do with if the load is linear or not.

Unless the manufacturers say that a certain duty cycle increases the permitted power dissipation it simply does not. There are many examples where engineers thought it did and ended up costing their companies a lot of money.

Bottom line, if you think this is a good idea it is not. If you fail to understand why then just take the advice and hopefully you will eventually learn enough about engineering.

However, if you think you are smarter than the manufacturers then you do not have the capacity to understand this subject and I suggest you take up knitting.

racemaniac:
I would expect not exceeding the power of the max rating (with fast enough pulses) to be safe since 40mA at 50% duty cycle would stress the circuit just as much as 20mA continuously (at the same voltage).
Which properties/effects come in play here that makes this not true?

It is called Ohm's law! :roll_eyes: (And the power equation.)

You do not seem to have comprehended my previous explanation.

The switching FET in the Arduino (ATmega328) behaves in a fashion as a resistor. This means that the more current that is drawn through it, the greater the voltage drop across it. If you care to read the datasheet, you will find this described.

This means that if you double the current you draw, you also double the voltage drop. The power dissipated is the product of these two, so doubling the current quadruples the power dissipated. It is as I said - passing double the current for half the time will double the power dissipation in the switching device.

Well, it would if the FET only behaved according to Ohm's law. In fact, they tend to function more as a current source. Please do not conflate them with a LED - there is absolutely no similarity whatsoever. This means that increasing the current more than doubles the voltage drop and more than quadruples the power dissipation.

Do you begin to get the message?

Paul__B:
It is called Ohm's law! :roll_eyes: (And the power equation.)

You do not seem to have comprehended my previous explanation.

The switching FET in the Arduino (ATmega328) behaves in a fashion as a resistor. This means that the more current that is drawn through it, the greater the voltage drop across it. If you care to read the datasheet, you will find this described.

This means that if you double the current you draw, you also double the voltage drop. The power dissipated is the product of these two, so doubling the current quadruples the power dissipated. It is as I said - passing double the current for half the time will double the power dissipation in the switching device.

Well, it would if the FET only behaved according to Ohm's law. In fact, they tend to function more as a current source. Please do not conflate them with a LED - there is absolutely no similarity whatsoever. This means that increasing the current more than doubles the voltage drop and more than quadruples the power dissipation.

Do you begin to get the message?

I indeed assumed your reply was also talking about the leds as some others were, but indeed, you were talking about the output pins (which basically was my question :slight_smile: ).
Where in the datasheet would i find what you mentioned? i looked in both the i/o ports section, and the electrical characteristics section, but couldn't find any more information than the standard ratings we all (should) know about. certainly not the nice curve you told about :).

I love to get to know these things a bit better, but asking deeper information on these "controversial" issues always sounds like you just committed a deadly sin on these forums :stuck_out_tongue: .

racemaniac:
Where in the datasheet would I find what you mentioned? I looked in both the i/o ports section, and the electrical characteristics section, but couldn't find any more information than the standard ratings we all (should) know about. certainly not the nice curve you told about :).

Ooh, that's funny!

You want nice curves?

I am looking at page 598, section 35.7, figures 35-21. "ATmega328P: I/O Pin Output Voltage vs. Sink Current (VCC = 3V)"
to 35-24. "ATmega328P: I/O Pin Output Voltage vs. Source Current (VCC = 5V)".

I am particularly impressed by the shape of those curves - except admittedly, those corresponding to operating the chip in a deep freeze. :grinning: They tell me something important.

(OK, perhaps not for the average man in the street, but for a true engineer, those are nice curves. :roll_eyes: )

I love to get to know these things a bit better, but asking deeper information on these "controversial" issues always sounds like you just committed a deadly sin on these forums

There is no controversy about it. It is just beginners who know very little think they have a bright idea only to find out they have not. Being their own idea they have a deep and irrational attachment to it, coupled by the attraction they they "know better" than conventional wisdom.
Given that then there are two sorts of people, the clever ones who take this advice and abandon their irrationalities and the stupid ones who will not be told very much and are doomed to be crap all their lives.

The deadly sin you have committed is not to do a simple google search and see how such stupid ideas have been greeted in the past and how nobody with any great record of successfully solving problems supports it.

Grumpy_Mike:
Do not confuse "currently not broken" with "work".

I should not have read that with a mouthful of coffee...

It is true, I did come here looking for what people think. I do not consider myself a noob to Arduino and definitely not a noob to EE, but I am a noob to this forum; and on that front I think I may have encountered an atmosphere I was not expecting. I don't know what can of worms (if any) I may have opened, but a few things:

1). A cap behaving exactly like a short, that is simply not true. That is true for DC steady state. I am talking PWM. That is neither steady state nor AC.

2). A MOSFET in saturation (again, steady state) does behave according to Ohm's law. It has parasitic RC on it. When not in saturation, Reff is substantially higher.

3). I'm failing to see how power dissipation during switching transients would exceed that of a MOSFET in full saturation mode? When output goes high, you charge the cap. When output goes low, you discharge the power to ground. Thus if thermal heat is the concern for overdriving it, you are spreading out the transients.

4). I'm not risking burning out a $25 Arduino; I'm risking burning out a $1.47 pro mini legal clone. I burn out more of those with my soldering. :slight_smile:

  1. finally my oscilloscope arrived yesterday, and I'm seeing actual peak current range from between 100-125mA. Above specs, but if I dumbly multiplied by 40% duty cycle, that meets the max spec.

6). My reason for dropping the resistor (if I can) is because I want to lose the breadboard. If we had resistive jumpers that would be awesome, but I am not aware of any. Actually...come to think of it...330ohm jumper wires...those might actually sell.

Has anyone tried crimping the resistor leads directly into the female jumper casing, and insulating the whole thing? Then you could just plug resistor directly to the header, then LED directly to the resistor.

racemaniac:
i would expect not exceeding the power of the max rating (with fast enough pulses) to be safe since 40mA at 50% duty cycle would stress the circuit just as much as 20mA continuously (at the same voltage).
Which properties/effects come in play here that makes this not true?

Just as a final word, what makes you think that with no resistor you will only get 40mA current flow. You are misunderstanding rating. The 40mA on an Arduino is not the maximum it will supply but the maximum you should let it supply. Just connecting an LED with nothing to limit the current will cause excessive current to flow from the Arduino. What stops the current going to infinity is the impedance of the output pin but that is insufficient to limit the current to a safe level.

1). A cap behaving exactly like a short, that is simply not true.

Wrong, a discharged cap looks like a short circuit at the instance a step voltage is applied to it.

I am talking PWM. That is neither steady state nor AC.

Wrong again PWM is AC, the current flows first in one direction and then another, that is alternating.

3). I'm failing to see how power dissipation during switching transients would exceed that of a MOSFET in full saturation mode?

That is your problem. Power is the product of voltage and current. When a FET is off there is lots of voltage and no current, so no power is dissipated. When a FET is on there is lots of current but not much voltage due to the low Ron resistance, hence not much power. When a FET is half on there is an appreciable amount of current and an appreciable voltage, at this point the power dissipated by the FET is at its highest.

4). I'm not risking burning out a $25 Arduino; I'm risking burning out a $1.47 pro mini legal clone. I burn out more of those with my soldering.

I don't give a flying F*** about the cost of anything. It does not mitigate you buring it out. It is this attitude that generates the most hostility to you.

  1. finally my oscilloscope arrived yesterday, and I'm seeing actual peak current range from between 100-125mA. Above specs, but if I dumbly multiplied by 40% duty cycle, that meets the max spec.

Yes it is a dumb thing to do, you can not equate the two, electronics do not work like that.