24VDC to uProcessor input

Discussion in 'The Projects Forum' started by tetsu0sh0, Mar 10, 2014.

  1. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    Hello All! First post here :)

    I would like to take a 24VDC signal and feed it into a microprocessor (VCC of 3.3v)
    I've considered a relay or an Opto-isolator. I'm new to microprocessors and I'm unfamiliar with what steps should be taken to protect the inputs.

    I'm leaning more towards the 24VDC relay because i'm more familiar with them. I've read this thread: http://forum.allaboutcircuits.com/showthread.php?t=93596&highlight=relay+switching and it seems to be a good solution but there is no schematic posted. It seems simple enough:
    Common - Input Pin of uProcessor
    Norm Closed contact: GND
    Norm Open contact: VCC via 10-100K Pullup.

    I'm pretty confident that solution will work, but relays have moving parts and they can fail. The input signal will be switching frequently and I'm concerned about the mechanical lifetime of my relays. Which is why I'm also considering an Optocoupler - longer lifetime.

    I have never used optocouplers before, and I can't really wrap my head around the implementation of one. I understand how they work: input signal lights an LED. Output is driven via a photo-sensitive switch of some sort.
    This would seem ideal to me because there's no moving parts, and the input is totally isolated from the output.

    Again, because I don't have experience with them I have a few questions. My main question would be how do you turn the thing on with 24V if it's a LED? Would I just need a large resistor to lower the current through the LED or do they have 24V versions of them?

    I realize this is a slew of questions, but my mind is swimming with them and I tried to ask only the important ones. If anyone has any input into the pros and cons of either of these ideas i would greatly appreciate it!
     
    Last edited: Mar 10, 2014
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    10 to 20k resistor will be enough. You can also add a small diode externally to Vcc.
     
  3. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    What purpose does the diode serve?
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    to clamp excess voltage. most modern uC have clamping diodes built in.

    One drawback with a larger resistor, you don't get a very high speed. Some 100 Khz are possible. And of course power is wasted.
     
    tetsu0sh0 likes this.
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    If you only need a low speed, such as a level you'd archieve with a relay, you can go higher, 50K or even more.

    You don't get a good transient response on the inputs of course but in some cases, does not matter. As each uC input acts like a small capacitor, sometimes info can be found like it would be 50pF but often is much lower.
     
  6. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    The switching speed does not matter.
    Thank you for your replies.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    Use a comparator like the LM393 or LM339. 24V input and open collector output. You can even set the threshold voltage.
     
  8. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    That would certainly be cheaper.
    How robust/ reliable would that be?
     
  9. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    IMHO the comparator solution is very robust. One of the inputs must be within the comparators Common Mode Range. Setting the threshold at 12VDC (Vcc/2) satisfies this requirement. Read the datasheet carefully for an explanation. It basically says don't let both inputs go to the positive rail or to GND at the same time.
     
  10. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,769
    969
    tetsu0sh0 likes this.
  11. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,515
    1,246
    An important issue is isolation.

    If you need galvanic isolation between the 24 VDC source and the uC, that is, the ground for the 24V signal and the ground for the uC are not the same, then a relay or optocoupler is required. If the grounds can be connected but the 24V signal is from an electrically dirty/noisy environment, a relay or opto is the best way to protect the uC input.

    A relay and opto are identical in that both outputs are single-pole switches and require a pull up or pull down resistor. Only two significant differences between the two. 1) The output of an opto is a semiconductor, so it has polarity. Unlike a relay, it matters which contact or output pin goes where. For the opto, the E (emitter) output goes to the uC ground. The C (collector) output goes to the uC input pin, with a pull up resistor to the 3.3V. There is another variation with the C to the 3.3 and the E to the uC input. Ask for details. 2) As you said, the opto input needs a current limiting resistor, plus an optional reverse-polarity protection diode. The series circuit is the +24 signal, diode, resistor, opto input A (anode). The opto K (cathode) pin goes to the +24 circuit ground.

    OTOH, IF it is a very benign environment, then all you need is a 2-resistor divider. Note the really huge IF.

    ak
     
    tetsu0sh0 likes this.
  12. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    The 24v and 3.3v share the same ground.
    24V is being supplied, and I'm using a switching regulator to knock it down to 3.3v.
    The 24V is being sent to a remote switch and the wires could pick up some noise. I can't find any specific voltage ratings for the input terminals? Is it safe to assume I just set a current limiter to supply 20mA to the input?

    From what I gather, the circuit would look like this (attached).

    How would I size the protective diode? I've never done that before.
     
  13. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,515
    1,246
    Good schematic. At only 24V and 20 mA, the diode can be just about anything. The 1A power diode series 1N4002 thru 1N4007 series will work. So will signal diodes like the 1N914 / 1N4148.

    The diode can be either in series with the opto or in parallel with it as you show. In series, no current flows if the 24V is connected backwards. In parallel, 20 mA of reverse connection current will flow, but the diode will prevent it from going through the opto. And reverse current will go through the opto. An LED has a reverse breakdown voltage just like a zener diode, usually around 6-8V. So without the protection diode in your schematic, a reverse connection should push about 13 mA through the opto, more than enough to turn on the output. While this looks like a polarity-independent solution, it is not recommended. The power dissipation in the LED is 4 times greater than normal, and the extra heat will affect long-term reliability.


    If you want the circuit to be polarity-independent like a traditional relay, you'll need either an opto with back-to-back LEDs inside (an "AC optocoupler") or a diode bridge instead of the single protection diode.

    ak
     
    tetsu0sh0 likes this.
  14. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    A polarity dependent solution is probably best. I'll just need to label my inputs and outputs as #IN+ and #IN-.
    And with that solution comes a modified schematic. (attached)
    As far as the diode goes, the 1N4001 has a blocking voltage of 100v. That should be sufficient right?
     
  15. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    1.2K is a bit low for 24V. I'd suggest at least 2.2K, or 3.3K
     
  16. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    a 3.3K resistor will supply a little more than 7mA to the diode.
    That's enough?
     
  17. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You can only be sure about that when you consult the datasheet for the optocoupler. Or you can just try when you build the circuit.
     
    tetsu0sh0 likes this.
  18. tetsu0sh0

    Thread Starter New Member

    Mar 10, 2014
    8
    0
    http://www.fairchildsemi.com/ds/MC/MCT6.pdf

    So in reference that data sheet, the maximum forward current is 60mA. If i use the 1.2K resistor, i'll only be at 1/3 of that value.

    From what I gather, this part would be acceptable, correct?
     
Loading...