November 12, 2009 by mikedoug Okay, now that I understand the behavior of the LEDs, I'm probing deeper at the behavior of the circuit driving my LED. In short, here is the circuit I'm analyzing: ``````Output pin PB1 (+5) <-n1-> GREEN LED <-n2-> 127.6 Ohm resistor <--> GND `````` When I have NOTHING connected to PB1, the meter shows 4.94V between ground and the pin (node n1). When I have the LED and resistor connected, it shows 4.50V. The change in voltage is what I'm off to investigate (I think I know the answer, but it doesn't make 100% sense, and I'm going to walk through a bunch of observations first.) Observations from multimeter: ``````Voltage @ n1 = 4.50V Voltage @ n2 = 2.38V Current from pin to ground = 16.96mA `````` These two things tell us: ``````Voltage across LED = 2.12V (excellent!) Voltage across resistor = 2.38V Voltage missing = 0.44 to 0.50V `````` By mere observation it would seem that there is a resistor inside the MPU associated with the IO pin being pulled high. Sure enough, page 72 shows an Rpu in-line with the +5 source. Page 304 lists the range for Rpu to be 20K-50K Ohm. Excellent, that would seem to be the answer to the question. However, let's look at my observations and calculate what the effective resistance value would appear to actually be: ``````Current through the pin = 19.96mA Voltage across internal resistor = 0.44V or 0.50V Effective resistance V / I = 25.9 Ohms or 29.48 Ohms `````` 25.9 Ohms does not appear to be in the range of 20-50K Ohms as listed on page 304. What's going on here? Further, if we go back to the no-led and no-external-resistor scenario, the voltage measures at 4.94, and it will source ~80mA of current. That leaves 0.06V to drop over the internal circuitry -- that would imply 0.75 Ohm Rpu resistor... Err? Thanks! MikeDoug Hi MikeDoug, It's not the pull-up resistor. Take a look at my first post on this thread, where I talk about how to look at the current-voltage curves of the microcontroller's output pins, and how I linearize and get about 30.8 ohms for the "source" resistance, and 26.6 ohms for the "sink" resistance, right from the graphs in the microcontroller's datasheet. This is right in line with your "effective resistance" calculations! As far as the 4.94 volts when the pin is not connected to anything... have you tried measuring the nominally +5V voltage coming out of your voltage regulator? The datasheet-specified tolerance on that is 5.0 +/- 0.2 volts at a specific temperature, and 5.0 +/- 0.35 volts over the full operating range. Additionally, you may still get some voltage drop between that and the output pin because the internal wiring of the chip (very fine wires between the VCC pin and the appropriate part of the silicon) has some finite resistance. The rest of your microcontroller is pulling some finite current through that wire, so there will be a small voltage drop, which is what you might see at that output pin. Hope that helps! Mike The voltage from the regulator is steady at 4.97V. Ah.. page 328 IS what I was looking for. At 20mA, the pin will supply in the range of 4.5V -- exactly what I see! That raises the question... when does the pull-up resistor affect your circuitry? Thanks Mike! Hi MikeDoug, The pull-up resistor has an effect when it's turned on, which is when the pin is configured as an input, and the correspond PORTxn bit is high. You've got the pin configured as an output, so there's no effect. Check out Figure 13-2 on page 73 of the ATmega168 datasheet. This shows an equivalent schematic of a single I/O pin. You'll see the pull-up resistance in series with a p-channel MOSFET, and you can see that the gate of that MOSFET is controlled by a logic function computed over the DDRxn, PORTxn, and the global pull-up disable PUD flag. Mike