0
\$\begingroup\$

I'm having a mental lapse. Try and help me make sense of a few basic things concerning microcontroller pins at the hardware level, please!

  1. Correct me if I'm wrong… in the circuit of Figure 1 (see attached image), TRIGGER leads to a GPIO pin of a PIC24F configured as an input. When the MOSFET (P) channel is closed, TRIGGER (i.e., the MCU input pin) will be +3.3 V. However, when the MOSFET (P) channel is open, the MCU input pin attached to TRIGGER will be floating because the opposite end of the resistor is essentially disconnected, correct? If this is not the case, why?

  2. Does a GPIO pin of a PIC24F configured as an input require a series current-limiting resistor as to not potentially destroy the pin from a given input? In other words, is one needed to make sure the impedance of the input signal is at a known value so as to know the current going into the pin?

  3. That said, what if you were to connect an input pin directly to a +3.3V voltage source with no series resistor? No blown pin, right? The pin would only draw as much current as allowed by the input impedance (I think), which leads me to ask, what is the input impedance of an input pin? The PIC24F can sink and source 18mA of current. What I'm trying to ask is, what's the purpose of a series current limiting resistor to an input pin if the pin already has impedance and will only draw up to 18mA? It's not like the +3.3V will be conducted directly to ground through the MCU (because the pin has impedance), right? Maybe I have this all wrong...

  4. Output pin question: I understand the purpose of a series current limiting resistor used for limiting current through an LED, as it could otherwise essentially become a +V to ground short (high current through the LED causing it to overheat and break). But if an output pin already has some internal impedance which would limit current anyways, why is an additional resistor in series the standard thing to do? The pin can only source up to 18 mA - I assume this is governed by the pin's internal impedance. How would the pin be capable of sourcing any more current? Obviously I'm missing something…

  5. Correct me if I'm wrong again… in the circuit of Figure 2, when the MOSFET (P) channel is open, TRIGGER is pulled low through the two resistors in series. When the MOSFET (P) channel is closed, TRIGGER will see +3.3V. No floating going on, right? Also, is the series resistor in-line with TRIGGER (1 kOhm) necessary? Or can I connect TRIGGER directly to the drain before the pull-down resistor (essentially directly to +3.3V)? This ties in with my previous question about series resistors with input pins...

These simple, basic questions have been gnawing at me for a while.

FIGURE 1

FIGURE 2

\$\endgroup\$
  • \$\begingroup\$ Re #3, the 18 ma sink/source value only applies to output pins. Input pins have very high impedance (~1MΩ) and draw only a few µA. \$\endgroup\$ – tcrosley Feb 19 '13 at 12:00
  • \$\begingroup\$ Thanks! Sinking and sourcing refers to current going into and out of the MCU (respectively), right? If you configure a GPIO pin as an output, why would current ever go into the pin? I suppose it depends what the output circuit looks like, if it's tied to the voltage supply rail or ground... maybe I just answered my own question...? \$\endgroup\$ – The_Ders Feb 19 '13 at 16:04
  • \$\begingroup\$ Yes, you can think of current either flowing in or flowing out. Whether a pin is sinking or sourcing refers to whether it supplying (sourcing) a positive voltage (e.g, VCC) to a load that is grounded (on), or grounding it (off). This called a push-pull configuration. Sinking refers to grounding (sinking) an output pin connected to a load which is in turn connected to a higher voltage. The latter are mostly associated with open-drain outputs, which are either at ground (off) or high impedance (on). This allows them to ground a load that is connected to a voltage much higher than VCC. \$\endgroup\$ – tcrosley Feb 19 '13 at 19:35
2
\$\begingroup\$
  1. So I'm not too sure I follow this first question here, but I'll take a stab at it: if Vin = 3.3V (i.e. your P-channel mosfet does not connect source and drain) then "TRIGGER" will essentially be disconnected, yes. This assumes that "TRIGGER" is connected to a high-impedance source, like an input pin on a standard microcontroller. As a quick note "essentially disconnected" means that there is a high impedance threshold to get across the source-drain junction, but it is not infinite. If Vin = 0V (i.e. source and drain are connected), then trigger will be close to (but slightly less than) 3.3V

  2. So an input pin on a PIC24F is high impedance. This means that it will behave like a resistor with around 1MΩ of resistance to ground. If you check the "Electrical Characteristics" section in the "DC Characteristics: I/O Pin Input Specifications" subsection in the datasheet for the chip you're using, you should find a table which gives you the "Input Leakage Current." Using the dsPIC33FJ256GP710A as an example (it was a datasheet I happened to have on my machine), it lists 0 to 3.5 μA as the leakage current into or out of a pin within the limits of those pins.

    So as a note, you'll also see that in the "Electrical Characteristics" section under the "Absolute Maximum Ratings" subsection, there will be a list which says something to the effect of "Voltage on any pin that is not 5V tolerant with respect to VSS(4) .... -0.3V to (VDD + 0.3V)". This is telling you that you can't put more than ~3.6V on any pin without damaging the pin. This doesn't mean that you should put a current-limiting resistor in front of the input pin, this means you should put a voltage divider in front of the input pin to limit the maximum voltage to less than VDD + 0.3V.

    To tie this into question #1: this means that when a digital input pin is connected to a high-impedance output source like Fig. 1, you will see oscillating input values (1 and 0 randomly) based on when that very small drain removes or adds enough electrons to jump from one digital state to another. This is called a floating input

  3. So I just answered this question in the previous one, but I should tell you: the "Maximum output current" is not internally limited. So although the PIC24F can "only output 18mA" this means that if you connect an output pin which is high directly to ground, it will output lots more than 18mA before it burns out! The 18mA is the maximum it can safely output without overheating/damaging the chip. This is true for both sourcing and sinking, there is no fuse which will stop you at 18mA, only the magic blue smoke.

    Just to reiterate: you can safely connect any voltage to a digital input pin within its range (-0.3V to VDD+0.3V for the dsPIC33F). It would not blow the pin to connect it directly to +3.3V, nor would it blow the pin to connect directly to ground.

  4. Just answered this in #3, but again, it's not the output impedance of the pin which limits this... Or, more accurately, it is the output impedance, but it will limit the currently by melting.

  5. And yes, you can safely remove the 1kΩ resistor from Fig. 2 without damaging your PIC.

\$\endgroup\$
  • \$\begingroup\$ Excellent response, thank you! This reinforces what the others have said. This clears up my initial questions perfectly. The root of my questions seemed to be that I didn't realize the impedance of a GPIO configured as an input was ~1MOhm (~no current). A few more for everyone: A. Pull-up/down resistors (whether internal or external) are then only needed for INPUT pins, correct? In contrast, a pin configured as an OUTPUT "knows what level it's at" because it does the driving - a floating OUTPUT pin doesn't make sense... do I have this right? \$\endgroup\$ – The_Ders Feb 19 '13 at 16:16
  • \$\begingroup\$ B. My response to @tcrosley : Sinking and sourcing refers to current going into and out of the MCU (respectively), right? If you configure a GPIO pin as an output, why would current ever go into the pin? I suppose it depends what the output circuit looks like, if it's tied to the voltage supply rail or ground... maybe I just answered my own question...? Sorry about the formatting of these comments. Can't get the linebreaks to work. \$\endgroup\$ – The_Ders Feb 19 '13 at 16:23
2
\$\begingroup\$

And the TL;DR (plus a little) version.

1) Yes. When "off" the pin is floating. (some MPUs have an internal pullup/down resistor you can configure, to make a safe level on the pin)

2) No. As long as the input pin voltage is between the supply rails, no resistor necessary and virtually no current.

3) No blown pin. The pin will only source/sink current if you configure it as an output. So if it's wired to 3.3V, don't do that. And if you do, don't output 0 on it...

4) Keep the resistor in the LED drive. Read the fine print : 18ma is guaranteed but you might get 60ma. Plus, the resistor dissipates power outside the CPU package. Drive enough LEDs directly from the CPU and it would get rather warm.

5) You can lose the 1K resistor.

\$\endgroup\$
  • \$\begingroup\$ Great info, clarifies things greatly! Thanks a bunch. \$\endgroup\$ – The_Ders Feb 19 '13 at 16:06

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.