Driving LED with PWM, Beginner's Question

Hi all!

True beginner here, but was very excited to find this site. I woul greatly appreciate if someone could shed some light on whether or not I a going about a project correctly. Here are the facts:

Using -

PIC16F690 with an external 20Mhz crystal oscillator, powered by 5V (a

300mA? at least that's what the wall wart says - seems to be about 1 am when I measure it).

I am trying to drive an LED with PWM on the CCP1 pin. I have written a app that uses 10 bit resolution for the duty cycle, and varies it between and 100%. This appears to be working correctly - the LED fades fro completely off to rather bright.

I am, however, trying to figure out whether I should have a resistor i series with the LED or not.

I am powering a blue LED. Its voltage rating is 4V, the current test i

20mA.

My best measurements with an oscilloscope and multimeter seem to indicat that at 100% duty cycle, the PWM pin is outputting 5V at 32.6mA. I don' know if this is correct, and would love to even know where in the datashee I could look to know what the pins can potentially output - is this calle sourcing, or sinking, a voltage?

Anyway, it seems to me that if:

R = (Vsource - Vled)/I

Then I should have a resistor of size:

R = (5-4)/.02 R = 1/.02 R = 50ohms (nearest greater = 56ohms)

So, my final questions are:

  1. Do the readings I've taken for the PWM pin at 100% duty cycle make an sense? How could I find in the data sheet for the PIC16F690 what the pi can "output"?

  1. I'm trying to get the most brightness possible out of the LED. If m readings are all right, it seems like this resistor in series with the LE is correct for 100% duty cycle. Do I need it when I'm doing PWM? Wha about at the smaller duty cycles, will this make it very dim?

Any help would be much, much appreciated!

-Syr

Reply to
syr123
Loading thread data ...

Without the current limiting resistor, the output port structure itself is limiting the available current. However:

Section 17.0 Electrical Specifications Absolute Maximum Ratings ... "Maximum output current sunk by any I/O pin 25 mA Maximum output current sourced by any I/O pin 25 mA Maximum current sunk by PORTA, PORTB and PORTC (combined) 200 mA Maximum current sourced PORTA, PORTB and PORTC (combined) 200 mA

"NOTICE: Stresses above those listed under ?Absolute Maximum Ratings? may cause permanent damage to the device."

The maximum brightness occurs just once, briefly, before it lets the magic smoke out. It is what it is and it's rated how it's rated.

With the caveat that you're not likely to be able to source all the way up to Vcc, particularly when driving near (or above) the rated current.

Yes. Never exceed a device's absolute maximum ratings. There may be instances where doing so is required and desired but if you have to ask, it safe to assume that it's not a particularly good idea. You *might* be able to get a slightly brighter appearance by overdriving the LED at less than a 100% duty cycle but you would have to run the numbers to determine all side effects. Probably beyond the present scope...

The perception of brightness is roughly a log function. A 10-bit PWM will do nicely for ten distinct brightness levels. The current is what the current is and you do need a resistor.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

Hi Rich -

Thanks so much for your prompt and informative follow up. Seems like this board will be a great learning experience for me.

Much appreciated!!

Best, Syr

Reply to
syr123

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.