24VDC to uProcessor input

Thread Starter

tetsu0sh0

Joined Mar 10, 2014
8
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:

takao21203

Joined Apr 28, 2012
3,702
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.
 

takao21203

Joined Apr 28, 2012
3,702
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.
 

Papabravo

Joined Feb 24, 2006
21,159
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.
 

AnalogKid

Joined Aug 1, 2013
10,990
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
 

Thread Starter

tetsu0sh0

Joined Mar 10, 2014
8
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.
 

Attachments

AnalogKid

Joined Aug 1, 2013
10,990
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
 

Thread Starter

tetsu0sh0

Joined Mar 10, 2014
8
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?
 

Attachments

Top