Question about design / input optocoupler - Page 1
Forum section: electronics / projects

author: stef_r
author_rank: Contributor
timestamp: May 08, 2014, 07:55:39 pm
content: Hi,I hope Dave, or someone else will take a look at a part of my circuit:What I want is to have a 'independent signal input' for a PIC controller.The outputs of the opto's are, ofcourse, connected to a pull-up resistor.Each output goes to a input pin of the PIC controller.On the input side, there can only be three known 'signals' present: 1) not connected, 2) positive supply signal and 3) a ground (or 0V) signal.What I want to do is create a circuit with three inputs.Each one of these inputs will eighter be a positive DC signal (like 12V or 24V) or a neutral / ground signal.These inputs are connected to a PIC: for my purpose the PIC doesn't have to know if the signal is a positive or a ground signal. It just have to respond onto the input.In my drawing above, each input will need two input pins on the microcontroller.Is this a 'good way' to think for me, or is there maybe a (much) simplified solution?I preferably use an optocoupler for safety reasons among some other reasons.My ideal circuit would be that each input would occupy one input pin of the microcontroller.But how hard I thought it over, I couldn't think of a smart, simple solution that does it all;Hope to get some good comments about thisOh, I forgot to mention the type of PIC I intended to use: The 16F1509 (with PWM capable output) or the 16F1829 (which has a bit more memory but no PWM output).

author: retrolefty
author_rank: Super Contributor
timestamp: May 08, 2014, 08:46:04 pm
content: Well one problem I can see is that if the unknown signal is at +12 vdc then the two optos will be in the same state as if there was no signal, as both led would still be in conduction. If signal is +24 then optos will show different states. Also be sure whatever is supplying the signal can sink/source the current the opto inputs consume.

author: dannyf
author_rank: Super Contributor
timestamp: May 08, 2014, 09:34:01 pm
content: It will work.However, unless you are looking for isolation, a simpler circuit with two resistors will also work.

author: Fank1
author_rank: Regular Contributor
timestamp: May 08, 2014, 11:02:32 pm
content: As drawn: With no signal both will be on. With the input grounded only A will be on and with 12V on the inputs both will be on.If you change the supply voltage to 12 v however then. No signal = both on, Ground = A on B Off, and with +12 = A off B on.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 08, 2014, 11:59:09 pm
content: You are attempting to measure three states:OpenHighLowA single pin can only read two states:10Therefore, more than one pin is required. Two pins is the absolute minimum. Two pins have these states:00011110Which is one more state than required; that one will simply go to waste (as shown, the 11 state -- both optos off, the input pins pulled high).If you go with signals other than digital, you can encode much more data to a single pin. But this will require control over the pull-up (which would be a variation on a muxed input), or an ADC input (which you may have available?). The ADC, of course, will take some time to measure and compute. If optoisolators are fast enough for your application, this probably won't matter.Tim

author: stef_r
author_rank: Contributor
timestamp: May 09, 2014, 07:59:36 am
content: Quote from: retrolefty on May 08, 2014, 08:46:04 pmWhat I forgot to tell is that the voltage at the input side is always equal to the supply voltage of the opto's.So if there supply voltage of the opto's is 24V, the positive input voltage will be 24V also.If the supply voltage is 12V, the input voltage is also at 12V.

author: stef_r
author_rank: Contributor
timestamp: May 09, 2014, 08:03:48 am
content: Quote from: T3sl4co1l on May 08, 2014, 11:59:09 pmNo, the PIC only needs to know if there is a signal present. This signal can eighter be a ground or positive signal. Also, for the application the PIC also doesn't have to 'know' if it is a ground or positive signal.

author: stef_r
author_rank: Contributor
timestamp: May 09, 2014, 08:06:55 am
content: Quote from: Fank1 on May 08, 2014, 11:02:32 pmThe fact that if there is no signal present that both opto's are on that's correct.I don't think I can make it that only one of the opto's will turn on when any signal (ground or positive) is present.So both input's on the PIC will be constant at a high state and one of the pins will go low if there is a signal present.

author: fcb
author_rank: Super Contributor
timestamp: May 09, 2014, 08:22:47 am
content: Whilst others have pointed out the binary nature of digital inputs, I would look at your system design. You allude to needing more than one of these trinary channels?Some suggestions:1. Stick with what you have as an input circuit and use one or more multiplexers (4051 etc..) to reduce pin count on your micro.2. Do some conversion on your signal before-hand, you could easily arrange for a 555 timer on each channel to change frequency or duty cycle depending on input voltage (crude ADC), then just couple through a single opto per channel.3. A simple ramp generator across all the channels, then just drive a single opto from a comparator looking at the input voltage.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 09, 2014, 01:06:08 pm
content: Quote from: stef_r on May 09, 2014, 08:03:48 amAh! Then you are only measuring two states, and it can be done through a single pin. An example would be, connect the phototransistors in series, with just one pull-up resistor. When both are on, the pin is held low; when any opto, or both, turns off, the pin rises high.Tim

author: dannyf
author_rank: Super Contributor
timestamp: May 09, 2014, 01:12:48 pm
content: QuoteThe pin goes high only if both optos are turned off.You described an ac opto, or two back-to-back (dc) optos.

author: Fank1
author_rank: Regular Contributor
timestamp: May 10, 2014, 12:51:29 am
content: Refer to my original post.if the input is floating there will be voltage drop across both inputs and they both will be on.if the input is grounded there will only be voltage drop across the top one and it alone will be on.if the input is 24 v then there will be voltage drop across only the bottom one and it alone will be on.Your circuit is good.

author: nctnico
author_rank: Super Contributor
timestamp: May 10, 2014, 07:09:22 pm
content: A lot of people forget this: if the input signal and the system have a common ground then there is no need for an opto-coupler. I have even seen opto couplers used behind an open-drain comparator chip connected to the same ground^100Regarding you circuit: I'd use 2 comparators so you can sense the input is grounded, floating or connected to 24V with a proper resistor contraption (and a zener diode to clamp the input signal). If your controller has an A/D converter you could use that as well.

author: stef_r
author_rank: Contributor
timestamp: May 10, 2014, 07:34:21 pm
content: Quote from: nctnico on May 10, 2014, 07:09:22 pmThe system will be used in a car so yes the input signal and the rest of the system will have the same ground conenction to the negative terminal of the car battery.So, therefor, you say the use of an optocoupler isn't needed?The PIC I would use is one of the Enhanced Mid-Range architecture (16F1509).If I would leave the opto's out, I'm not sure how to design the comparator / A/D Converter circuit...(I'm learning the way through...)Also, the complete project would use three of these opto circuits so if I can simplify it with the method you mention that would be fantastic!

author: retrolefty
author_rank: Super Contributor
timestamp: May 10, 2014, 09:01:28 pm
content: Quote from: stef_r on May 10, 2014, 07:34:21 pmIf the input circuit and output circuit of an opto share the same common ground then galvanic isolation is lost, so what is the purpose of using the opto Vs other voltage clamping/protection methods.

author: stef_r
author_rank: Contributor
timestamp: May 11, 2014, 10:40:26 am
content: Quote from: nctnico on May 10, 2014, 07:09:22 pmHope you don't mind asking, but can you help me get started with this?If I want to use the ADC function of the PIC 16F1509, how would I start with the hardware circuit for it?Can it just be with a zener diode and a resistor at the input side?

author: Dinsdale
author_rank: Regular Contributor
timestamp: May 12, 2014, 02:09:30 am
content: QuoteThe electrical environment in an automobile (or any vehicle) is one of them most hellacious there is. CPUs targeted for this use have many protection features built in that allow direct connection to 12 and 24V systems. Your PIC or Arduino does not have any of these protections. The ground loops in a car can be large depending on the various and constantly changing demands being placed on the system. You can not depend on the ground connection you are making at your processor module being the same as the ground level from the particular device from where you are getting your input signal. Even if you measure it statically in your driveway and it looks OK, turn signals, break lights, headlights hi/low, windshield wipers, fan motors, air conditioning, and even road shock, will change that level randomly.Unless your CPU and signal source are very close to the battery, opto coupling these inputs is essential in your application. Isolation from ground loops and 12/24V is a practical safety measure. You might burn out an optocoupler, but your CPU should survive.

author: fcb
author_rank: Super Contributor
timestamp: May 12, 2014, 01:02:53 pm
content: Quote from: Dinsdale on May 12, 2014, 02:09:30 amTosh.You won't find a single opto-coupler in a car.Just design your power-supply to cope with 'load-dump' and work out what your inputs have to suffer and design accordingly.

author: Dinsdale
author_rank: Regular Contributor
timestamp: May 12, 2014, 03:28:32 pm
content: Well, you won't find very many, that's for sure. CPU based automotive modules are designed at a system level which includes the transducers that they monitor. The transducers help to isolate the computing system from the power distribution. The OP is tying a 5v (or less) micro directly into the power distribution (if I understand correctly). He probably should use a DC sensor meant for the purpose. But in this case, the optos are his transducer. Good enough for a learning experience; not good enough for commercial automotive application.

author: stef_r
author_rank: Contributor
timestamp: May 13, 2014, 05:54:57 pm
content: Quote from: Dinsdale on May 12, 2014, 03:28:32 pmWell, ofcourse I have designed a suitable power supply for the PIC with use for in the automotive: (at least IthinkI have...)I've used a RB040-40G for reverse battery protection and load dump.A small filter and some cap's in front of the voltage regulator.I think this would not a very bad power supply design for use in an automotive environment.......

author: stef_r
author_rank: Contributor
timestamp: May 13, 2014, 06:53:39 pm
content: Quote from: Dinsdale on May 12, 2014, 02:09:30 amMaybe a stupid question, but what would be the best way to create a galvanic isolation between the cars ground and the 'digital' ground?I've seen examples with 4 diodes but I think they would only suitable for AC applications, right?Or would a single capacitor between the two ground be sufficient enough?Sorry for all these questions but this would be my first 'real' automotive design / project..Also, if you have any suggestions about documentation or info about electronics design for automotive applications, I would greatly appriciate if you want to share those!