This is my first project using a 3.3v microcontroller (the Artemis Nano), and I’m confused by what I’m seeing in regards to Vf and If on my LED circuit.
I have a 5mm 940nm IR LED that according to the mfg has a Vf of 1.2v, and If of 20mA. I am driving the LED from Analog pin A3, with 100% duty cycle, with a 1/4W resistor in series. I am experimenting with different R values to see what makes the most sense, however I am confused by what I’m seeing.
Using R = V /I, I calculate that (3.3v-1.2v)/20mA = 105ohms. However when I use a 100 ohm resistor, and I take measurements at the LED, I measure a Vf of 1.21v, andIf of 15.4mA. There is a big difference between 20mA and 15.4mA. So moving down to a 91 ohm resistor, and using I = V/R, I calculate that (3.3v-1.2v)/91 ohms = 24mA. However when I use a 91 ohm resistor, I measure a Vf of 1.21v, and If of 16.2mA. Again, big difference between 24mA and 16.2mA.
Can someone explain why my actual values are so far off from calculated values? I know that using a PWM duty cycle of anything less than 100% could confuse my results, but in these tests I am only using a PWM value of 255. And when I put a voltmeter on pin A3 with nothing attached, I am measuring 3.25V.
I’m sure I’m missing something obvious here, thanks in advance for the help!
Based on a quick review of the datasheet for the Apollo CPU used by the Artemis module, it looks like GPIO pins max out at 16 mA, so if you’re driving the LED directly from the GPIO pin, that’s likely what you’re seeing. If you use the GPIO to control a BJT as a switch for the LED, then you’ll likely see something closer to the 20-24 mA that you’re expecting.
No, you can still use the PWM to dim the LED. All the PWM is doing is repeatedly switching the LED on and off so fast that to the human eye it appears dim. The BJT is merely changing the power source for the LED from the MCU to the 3.3V supply.
mdancer:
Based on a quick review of the datasheet for the Apollo CPU used by the Artemis module, it looks like GPIO pins max out at 16 mA, so if you’re driving the LED directly from the GPIO pin, that’s likely what you’re seeing. If you use the GPIO to control a BJT as a switch for the LED, then you’ll likely see something closer to the 20-24 mA that you’re expecting.
Okay so I did a bit more testing, this time under the 16mA max GPIO threshold, but still have confusing results. I bumped my R up to 150ohm, so I’d expect to see something like (3.3v-1.2v)/150ohm = 14mA. However I’m measuring a solid 11.5mA, which is about the same variation from expected that I saw with values above the 16mA max. So if I’m within the output specs of the GPIO now, what else is at play here that is affecting the output this drastically?
Things I have done to rule out possible explanations…
Switched to different GPIO pin. Same result.
Swapped LED and resistor with new stock. Same result.
Hooked up LED and resistor directly to LiPo pack. What I expected AND measured was (3.7v-1.2v)/150ohm = 16.6mA.
Loaded up the ‘Blink’ example sketch and simply drove the LED with a digital HIGH/LOW value. Output still measures 11.5mA.
Would really love to understand what’s going on in this setup. I’m trying to learn more about power consumption and optimization, and not understanding the math behind this is bothersome. TIA!
Try measuring the voltage from the output pin to ground. Then use that to calculate the current. From the data sheet (page 794), Voh (min) is 0.8*Vddh, so the output may be as low as 2.64V
Looks like you were on the money with this. With my load on the pin, the voltage from pin to ground drops to 2.87v. (2.87v-1.2v)/150 = 11.1mA. So much closer to my measured amperage. Thanks for figuring out where my math was wrong.
So the lesson here is to take the voltage drop into account. I’ve dealt with voltage drop with larger circuits and heavier loads, but didn’t realize it would be so significant at this scale.
jremington:
These are nominal values. You should not be surprised at 20% or larger variation.
Thanks, another good thing to remember. However in this case the values were really close to actual. Connected directly to my regulated 3.3v power source and an R of 100, I measure: 1.21v and 19.76mA at the LED. Much bigger issue causing my confusing was not accounting for voltage drop on GPIO.