Shop OBEX P1 Docs P2 Docs Learn Events
"Inverted transistor" Control small current with large current — Parallax Forums

"Inverted transistor" Control small current with large current

Harrison H JonesHarrison H Jones Posts: 22
edited 2009-10-10 23:36 in Accessories
Hello Parallax Sensors Forums,

I have a simple question I'm hoping has a simple answer. I'm trying to detect if a reed relay is tripped. I'm going to run +5 through it and I want to detect wither or not it is open/closed. I was thinking about opto-isolating it w/ a chip but I Was wondering if there was another way. A simple resistor wouldn't work would it? I don't want to blow my propeller's pins [noparse]:([/noparse]

Thanks for the help!

Post Edited (Harrison H Jones) : 10/3/2009 5:03:57 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 02:58
    Assuming there's nothing else connected to the reed relay's contacts, it's like any other switch. You connect one end of the relay to +5V. You connect the other end of the relay to a 10K resistor and a 1K resistor. The other end of the 10K resistor is connected to ground. The other end of the 1K resistor is connected to the Propeller I/O pin. The I/O pin will normally see a logic low (0). When the relay is closed, the I/O pin will see a logic high (1).

    There are examples of this in the Propeller Education Kit tutorials.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 03:09
    How do you guys know what values of resistors to use? Does it explain it in the Prop Edu kit tutorials? I have a very basic understanding of electronics and have never understood this.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 03:22
    It's all Ohm's Law and common sense.

    You've got +5V to work with. You want the switch (reed relay contacts) to conduct a little bit of current, but not waste too much. 1mA is usually enough current through a contact to keep it clean and, with the circuit capacitances, you won't get much delays charging things up. 5V / 1mA = 5K. A nice round number close to that would be 10K. You'd have about 1/2 mA and that's ok.

    The Propeller pin normally operates at 0-3.3V. Anything one diode drop (0.6-0.7V) beyond that will cause the built-in protective diodes to conduct to either Vdd (+3.3V) or Vss (0.0V). 5V - (3.3V + 0.6V) = 1.1V. The protective diodes are rated at 0.5 mA, but are a bit more robust than that. A 1K resistor will limit the current from the +5V supply to about 1mA. If you want to play it safe, use a 2.2K resistor which will limit the current to under 0.5mA.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 04:03
    Mr. Green,

    Thanks for the information. I understand Ohm's law I just wasn't sure of how to apply it. As I said, I have a very basic understanding of electronics. I understand that the 10K resistor is to "ground" the input pin such that it doesn't float. I understand that the resistance has to be high enough such that when the switch does close most of the current goes through the input pin and not to ground. I'm still a little confused.

    If I only had the resistor on the pin(the 1k) wouldn't that drive more than 1ma though the stamp? How do I model the stamp on a schematic? Is it a resistor? inductor? capacitor? mixed?

    If you have time, could you please explain a little more?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 04:27
    "If I only had the resistor on the pin" ... No

    CMOS IC inputs are high impedance. Virtually no current flows after a brief surge to charge up the capacitance of the gates on the chip.

    A microprocessor or any complex chip is represented by a box with the pins/leads labelled with the signals present (from the standpoint of the complex chip). Look at any schematic, like on the web. You'll see.

    Again, the reason for the 10K resistor is to provide a "default" signal (ground) when the switch is open. If you left out the resistor, the input pin would "float". It's a high impedance and would respond to random electrical fields and static electricity from the world around. Try it some time. Connect a microcontroller input pin to a long piece of wire (like maybe 30cm). Write a program to display the state of that input pin then wave your hand over the wire. You'll quickly see that your hand only needs to be close to the wire for the input pin to react.

    You want the resistor to be something like 10K rather than perhaps 1K or less so that you don't waste current heating up the resistor (a little) when the relay is closed. That would connect the resistor across the 5V supply. If the value is 10K, roughly 0.5mA flows. If the value is 1K, roughly 5mA flows. If your microcontroller is running off a battery, that amount of current could deplete the battery over a couple of days. A Propeller running at low speed may only draw 50uA or less. A Stamp in SLEEP mode might draw the same.

    Post Edited (Mike Green) : 10/3/2009 4:37:41 AM GMT
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 04:56
    Ok, so... Let me get this straight: We put the 10K resistor between ground the the switch to do two things: 1. establish the current though the resistor and 2. ground the input pin. I'm still a little confused however. How does the 1K resistor limit the current to .5mA?

    Also, concerning "drawing" the micro-controller. I realize it's a box w/ all the pins coming out... but how is it modeled? It sounds like it resembles a very high resistor connected to ground(Kinda like a volt-meter?). How high of a resistor are we talking?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 05:11
    The Propeller datasheet indicates that the leakage current for an input pin is on the order of 1uA. That would represent a resistance roughly on the order of 3M. In addition, the datasheet indicates that the capacitance of an input pin is roughly 6pf. In both cases, we're talking about the relationship to either voltage rail (Vdd or Vss). For more details (like the behavior of output pins) refer to the datasheet.

    When the relay is closed, the contacts connect +5V to one end of the 1K (or 2.2K) resistor that's connected to the I/O pin. The 10K resistor really doesn't enter into this case. The Propeller's I/O pin has a diode built into the structure connecting the I/O pin to Vdd (3.3V) so it will conduct if the I/O pin voltage is raised above 3.3V + 0.6V = 3.9V. The 0.6V is the voltage drop across the diode. With 5V on one end of the 1K resistor and 3.9V on the other end, the resistor will have to drop 1.1V. That allows a current of 1.1mA to flow through the resistor and protection diode. The protection diode probably can withstand the 1.1mA for a while although it's rated to withstand a current of 0.5mA indefinitely. Like I said, use a 2.2K resistor if you want to play it safe. That will limit the current to under 0.5mA (an exercise for the reader!)
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 15:34
    Ok Mr. Green, I'm getting closer to understanding. Firstly, I did your math. The 2.2K resistor would drop it to exactly .5mA and the 1K resistor would drop it to 1.1mA. Now, I think I've pinpointed the part I don't quite get. I don't understand how you can simply "pick" a voltage you would like to drop it to and add a resistor to get a current value. I thought the amount of current draw was dependent on the device. Does the propeller's input pin draw about that much power?

    By the way, thanks for all the help!
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 16:08
    I mentioned Ohm's Law. There's also Kirchhoff's Law (en.wikipedia.org/wiki/Kirchhoff's_circuit_laws) ... The Wikipedia is your friend ...

    When the input voltage to a Propeller pin is greater than Vdd (normally 3.3V) plus one diode drop (roughly 0.6V ... a function of the materials used to construct the diode and the construction of the diode itself), the "protection" diode will begin to conduct. It will conduct whatever current is available until it either burns out or something else catastrophic happens to the chip. The purpose of the 1K or 2.2K resistor is to limit this "fault" current to something the chip is designed to survive. This mechanism (protective diode) is intended to help the I/O pin circuitry handle static electricity and similar brief, low current discharges. It's also useful for providing a simple mechanism for the I/O pin to handle logic inputs that are greater than 3.3V ... by adding a current limiting resistor.

    Normally, when the input voltage to a Propeller pin is in the "normal" range (0V to 3.3V), it draws virtually no current (less than 1uA). It's only when the applied voltage is outside this range that these protection diodes come into play.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 16:15
    I find it interesting that you keep mentioning things I'm learning in my ECE class. I'm very familiar with Kirchhoff's law and have used it many times to solve circuit problems in class.

    Anyways, I'm still not sure why we are using 1ma as our "standard." If the propeller only draws 1uA why don't we do all our calculations using that number? I guess my problem here is that we have two unknowns(Voltage and Current) and, to me, you seem to be arbitrarily setting on of them(voltage = 1.1V) and then calculating current(V=IR).
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-10-03 17:14
    3.3v + 0.6v = 3.9v

    5v·─ 3.9v = 1.1v
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 17:22
    No, I understand WHERE he gets the number from i just don't see how he can "pick" that number without knowing the current draw. If the current draw is really 1uA then why did we use 1mA?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 17:31
    Re-read the note from 9:22pm yesterday regarding why 1mA.

    The voltages are fixed (5V, 3.3V, 0.6V) by the power source, choice of devices, and physics.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-03 18:11
    Hmm.. Ok. Lets see if this helps me: What If i decided to put a 10M resistor between the switch and ground. Then, I put a 500k resistor between the pin and the switch. That .002mA of current through the pins. Why wouldn't that work?

    I really really don't understand how you can regulate voltage w/ only a resistor if you don't know the current draw of the prop on a pin
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-03 18:49
    With a high resistance (10M) between the switch and ground, circuit capacitance will begin to play a large part in the behavior of the circuit. This includes stray capacitance. The RC time is high enough to matter. You may also get induced currents that are significant from other objects nearby (via the capacitance between them and the switch and the wires attached). Depending on the materials used in the switch contacts, you may get problems with oxides and other "dirt" on the contacts vs the very low currents involved (2uA or so).

    The Prop is a non-linear conductor. For voltages in the normal range, it has a roughly fixed leakage of about 1uA. For voltages outside that range ( > 3.9V or < -0.6V), it has near zero resistance and will conduct whatever current is applied up until the device is destroyed. This isn't exactly right, the details are actually different, but it's roughly what happens. There are also capacitance effects involved as well, so there is a charging surge involved to charge the input gate capacitance.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-04 03:43
    I feel really bad to keep doing this but I'm still not at a point where if someone asked me "Why" I picked these resistor values I could tell them with any understanding.

    So far the limit of my electronic knowledge limits me to knowing how to model resistors, capacitors, inductors, variable voltage supplies, current sources, and constant voltage supplies. Is it possible to model this circuit(With the reed relay, resistors, and prop) with only those components? So far I'm thinking of the prop as a resistor with 3.9M ohm resistance. The problem with that model is that if the prop only allows a current of 1uA though it that means only 1uA is going through the 1K resistor which doesn't allow for enough voltage drop.

    Should I model the propeller another way w/ those components or is it beyond the scope of my knowledge?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-04 04:00
    You can model part of an I/O pin by using several parts. There's a diode from the I/O pin (anode) to Vdd (cathode). There's another diode from the I/O pin (cathode) to Vss (anode). There's a roughly 3M resistor from the I/O pin to Vdd and another roughly 3M resistor from the I/O pin to Vss. These are not really resistors, but leaky reverse biased junctions that can leak either to Vdd or Vss or both depending on the voltage applied. The maximum current is roughly 1uA.

    The 1K resistor is there mostly to protect the diodes which become forward biased at voltages beyond the Propeller's normal operating range for an I/O pin. If the current through these diodes is too high, they and their interconnections on the chip can overheat and melt. The excess current through the Vdd and/or Vss busses on the chip can cause voltage shifts due to I x R drops and the inherent resistance of the on-chip power wiring and these voltages can damage other parts of the chip.
  • dev/nulldev/null Posts: 381
    edited 2009-10-04 20:40
    Wow I really enjoyed reading this thread, as I had the same kind of conceptual problems and frustrations learning to use microcontrollers. A simple and "safe" way of looking at the pins of a microcontroller in input states, is that they are wires going to Vdd or ground.

    Most electric circuitry have fixed voltage sources (they don't tell you in ECE class).

    Most microcontrollers use TTL or CMOS voltage levels. That means your voltage is fixed at around 5V or 3V. So voltage is a constant, and you vary the resistance (or impedance) to get the appropriate current through your circuit parts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy

    Post Edited (dev/null) : 10/4/2009 8:45:24 PM GMT
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-10 04:27
    I'm back!

    Ok, here's the situtation. Even though y'all have been very helpful I'm still having a hard time understanding this resistor problem. I talked with my ECE professor and we came up with the following circuit:

    attachment.php?attachmentid=64317
    (If it doesn't show up see the attachment)

    This "way" of doing it makes much more sense to me. All the resistances can be calculated given the desired voltage drops because they are all on the same "loop" (I1). Since the prop isn't going to consume that much power we can treat it like a broken wire and this we can use KVL analysis.

    Would this way work?

    I don't have time right now but I'm also going to put up the circuit for the other way(with the resistor(R1) going to the prop pin) and I'm hoping y'all can explain exactly how to find the reistances w/ some kind of analysis I'm used to.

    Post Edited (Harrison H Jones) : 10/10/2009 4:34:50 AM GMT
    450 x 303 - 10K
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-10 05:03
    The Prop will have a high impedance input only for voltages less than about 3.9V. If you use a voltage source of 3.3V, you'll be fine assuming that the Prop pin presents a nearly infinite resistance. Remember that there's a diode from the Prop pin to a voltage source of 3.3V. It'll conduct for some values of R1 and R2 if you have a 5V source on the left.
  • Harrison H JonesHarrison H Jones Posts: 22
    edited 2009-10-10 23:36
    It's amazing how the human brain works.. I was on my way home from a community service event, listening to some music, when suddenly, out of the blue, is understood the original circuit(With the resistor going to the pin). I wasn't even thinking about it.. I just suddenly understood. Sometimes I swear I can be so dumb.

    @Mr. Green - Thanks for all the help. I realize it must have been trying to deal with me when the answer is so simple and obvious.

    When I get time later tonight I'm going to post my "solution" with math and all for the other circuit to help any other forums members out. If anyone would be so kind as to check that solution when I post it that would be greatly appreciated!
Sign In or Register to comment.