Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Digital I/O

  1. Jul 20, 2006 #1
    Hi,

    I'm trying to control some solenoid valves and sensors with a microcontroller and I'm not sure what type of circuitry might be used to best accomplish this. For the outputs I think a ULN2003AI made by Texas Instruments might work but for the inputs I'm not real sure what I need to take into consideration. The sensors I'd like to read consist of 8 inductive proximity sensors (NPN) and 1 photoeye (NPN). Any help would be greatly appreciated.

    Thanks
     
  2. jcsd
  3. Jul 20, 2006 #2

    berkeman

    User Avatar

    Staff: Mentor

    Which uC are you using? Is it a 5V part or 3.3V part? What are the output voltages of your sensors? What are their [tex]V_{OH}[/tex] and [tex]V_{OL}[/tex] output voltages? Are the outputs noisy and bouncy, or are they cleaned up with hysteresis already? How long are the wires to the sensors?
     
  4. Jul 21, 2006 #3
    Thank you for the reply berkeman.

    I'm using an ATMEGA32 uC run at 5V. The sensors are powered by a 12V supply and VOH = VCC and VOL = 0V. The outputs are cleaned up with hysteresis and the wires are 8ft max.
     
  5. Jul 21, 2006 #4

    berkeman

    User Avatar

    Staff: Mentor

    Which Vcc? The 5V or 12V supply? If the sensor output VOH values are 12V, then you'll need to limit them to 5V at the uC inputs. You can use a series dropping resistor and diode clamp to 5V for that.

    After any clipping at 5V, it sounds like the sensor outputs are pretty well-condidioned to run into the uC directly. One thing I would do, especially with 8' cables, is to use diode clamps to the rails on each IO line where the cable comes into your uC board. This is done almost always on IOs like that, in order to protect the uC inputs from ESD and other transients coming in the IO cable. For each line, you connect a diode up from ground to the IO (anode=GND, cathode=signal), and from the IO up to 5V (anode=signal, cathode=5V).
     
  6. Jul 21, 2006 #5
    Sorry, VOH = VCC = 12V.

    Should the diode clamps come before or after the series dropping resistor?

    At the risk of showing how new to this stuff I actually am I must ask...how do you calculate the value of the series dropping resistor so that 12V is reduced to 5V? My hangup is the current portion of ohm's law...if this fluctuates at all the reduced voltage will fluctuate also.

    Also is there a way of dropping the voltage to safe levels that will work with a range of possible output voltages from sensors? This way the circuit would be more flexible.
     
  7. Jul 21, 2006 #6

    berkeman

    User Avatar

    Staff: Mentor

    The connection goes sensor, resistor, diode clamps at the uC IO input. The 5V clamp diode keeps the IO voltage from getting above about 5.7V (to avoid latching up that uC input pad), and the resistor limits how much current the diode has to catch.

    The resistance needs to be big enough to keep the clamp current small (say a couple mA), but small enough that it doesn't cause too much of an RC lowpass filter effect on the signal going to the IO. So let's target 1mA as a round number first, which would give you a resistance of (12V-5V)/1mA = 7kOhms. That's pretty big if your signal is fast, since 20pF of IO input capacitance and that 7kOhms has a lowpass filter corner frequency of [tex]\frac{1}{2 \pi R C}= 1.1MHz[/tex] For slow IO signals that should be fine. But for a clock or high-speed sensor signal, that kind of round-off on the signal can be a problem. The tradeoff is that you burn more current in the 5V clamp diode if you need to go faster with a smaller resistance value.
     
  8. Jul 21, 2006 #7

    berkeman

    User Avatar

    Staff: Mentor

  9. Jul 21, 2006 #8
    Thanks again berkeman for your help. I think I have a fair understanding of how all this works now.
     
  10. Jul 21, 2006 #9

    NoTime

    User Avatar
    Science Advisor
    Homework Helper

    Opto-Isolators might be a better idea than diode clamp.
    Worth looking into for remote sensors.
     
  11. Jul 21, 2006 #10

    berkeman

    User Avatar

    Staff: Mentor

    That's a very good additional suggestion by NoTime. Optos have limitations, but the biggest one is usually how to get power to both sides of the opto interface. But the OP said that the sensors had 12V power, and the uC side has 5V power, so an opto level translator and noise isolation would be a definite possiblity. The OP can check out the 4N25 jellybean opto datasheet for more info.
     
  12. Jul 24, 2006 #11
    Yes, thank you NoTime for the additional suggestion. I'm not sure if an opto-isolator would give me much additional protection though because the main system supply is 12V (used for sensor VCC) which is dropped down to 5V using a 7805 regulator for the uC. In other words the power supplies are not isolated.
     
  13. Jul 24, 2006 #12
    I have seen a 74hct245 chip used in circuits that provide the types of inputs that I'm looking for. Can somebody explain how this chip might accomplish the voltage level translation that I require?
     
  14. Jul 25, 2006 #13

    NoTime

    User Avatar
    Science Advisor
    Homework Helper

    One point of the opto-isolator is that you can easily do level transforms with one, in addition to general protection from the sensor and its environment.

    IIRC the 245 is just a buffer/line driver chip, not specific to level conversion.
    There are any number of ways to accomplish this task.
     
  15. Jul 26, 2006 #14
    The only reason that may make some sense for the use of the 74hct245 would be with a sensor that has a VOL that is not low enough for TTL logic levels. It seems like the 74hct245 has a much higher VOL on its input side which will produce a TTL compatble low on its output side.

    In any case it seems like an opto-isolator is the best all around solution. The only problem is I've never used one and don't know how a circuit that provides opto-isolated inputs might be designed. Can anybody point me in the right direction?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?