Detect AC or DC on same lead

LST

Joined Jan 17, 2020
12
Could someone give me some ideas?

I have a mains line that's entering a circuit. It goes to an optocoupler so the 110VAC is isolated from the circuit.

That line could have mains 110VAC OR if it doesn't have mains 110VAC it's going to have either 12VDC or 0V.

All logic is handled by a microcontroller so if the output of the optocoupler is +5VDC, I know that it's 110VAC and nothing more is needed but if output of the optocoupler is low, I need to further determine if there is 12VDC or 0V on the line.

Any thoughts appreciated.

AlbertHall

Joined Jun 4, 2014
10,068
You could perhaps use another optocoupler which will work with 1mA input current (e.g. PC355NJ0000F ) with a series diode (e.g. 1N4004) and 10k resistor. A reverse diode across the opto coupler input would probably be needed.

With 100V AC you can detect that already. The second optocoupler will also detect this with about 0.6W disipated in the resistor and 11mA in the opto coupler LED - well within its maximum rating.
With 12V DC your present system will show no 110V is present, but the new opto coupler will have the 1mA in the LED and will detect the 12V.
With 0V neither opto coupler will have an output.

crutschow

Joined Mar 14, 2008
25,132
Rectify the AC to give DC and then use a 1mA, 2-transistor BJT constant-current circuit at the opto input.
That will allow detection of both 120Vac and 12Vdc.
The maximum dissipation in the circuit should be no more than about 300mW

crutschow

Joined Mar 14, 2008
25,132
The second optocoupler will also detect this with about 0.6W disipated in the resistor and 11mA in the opto coupler LED - well within its maximum rating.
How did you get that dissipation for 11mA through a 10k ohm resistor?

panic mode

Joined Oct 10, 2011
1,837
BJT would need to be able to handle that voltage

AlbertHall

Joined Jun 4, 2014
10,068
How did you get that dissipation for 11mA through a 10k ohm resistor?
There is a series diode which halves the power (that's why the diode is there).

AlbertHall

Joined Jun 4, 2014
10,068
BJT would need to be able to handle that voltage
Which BJT and what voltage? The transistor in the coupler only needs to handle the 5V for the micro.

crutschow

Joined Mar 14, 2008
25,132
BJT would need to be able to handle that voltage
Of course.
There is a series diode which halves the power (that's why the diode is there).
Right.
I was thinking it was inverse parallel with the input.
With 0V neither opto coupler will have an output.
Why do you need two optos?

crutschow

Joined Mar 14, 2008
25,132
Below is the simulation of Albert's circuit using one opto:
You could periodically (say every 10ms) sample the output (yellow trace) with the micro to see if if was 0V (no input), steady 5V (12Vdc in), or varying (120Vac in).

View attachment 197098

AlbertHall

Joined Jun 4, 2014
10,068
Below is the simulation of Albert's circuit using one opto:
You could periodically (say every 10ms) sample the output (yellow trace) with the micro to see if if was 0V (no input), steady 5V (12Vdc in), or varying (120Vac in).

View attachment 197098
I was thinking two opto's as you need to be able to separate detection of the two different voltages but you are quite right that you can do that by the micro detecting pulses for AC.

LST

Joined Jan 17, 2020
12
Thank you crutschow and AlbertHall.

Conceptually I like the creativity of crutschow's sampling solution but I'd actually prefer the simplicity and less processor intensive nature of AlbertHall's 2 opto solution.

I'm pretty sure I got it. Thank you for the suggested component part numbers as well as examples. If there were any way for you to represent your idea in a schematic and post, that would be great. Thanks.

AlbertHall

Joined Jun 4, 2014
10,068
Like this:

LST

Joined Jan 17, 2020
12
I guess what I was looking to confirm was the placement of your suggested second optocoupler in relation to my existing first optocoupler. Could you show the schematic with the 2 optocouplers? Thanks much.

AlbertHall

Joined Jun 4, 2014
10,068
I don't know the schematic of your existing opto design so that's, to say the least, difficult.
The left hand side of the circuit in post #12 connects to the 110V/12V supply and the right hand side has a resistor and a connection to the micro. To be able to distinguish between 119V AC and 12V DC the two opto's would need to be connected to different micro pins if you don't want to be trying to spot the pulsed character of the output from #12 on AC supply.

LST

Joined Jan 17, 2020
12
I understand and agree and definitely need to have connections to different micro pins.

But I am still unable to picture the 2 opto circuit in it's entirety.

Without incorporating it into my specific opto design, but seeing any 2 opto design to detect 110VAC or 12VDC on the same leads would be helpful.

If you or anyone could suggest the placement of a first opto relative to the second shown in AlbertHall's post #12, it would help.

AlbertHall

Joined Jun 4, 2014
10,068
Show us your design and I'll join them together.

crutschow

Joined Mar 14, 2008
25,132
Don't know what happened (?).
Okay, here it is again.

If you want to use two optos, you could AC couple one with a series capacitor (which could be sized to also limit the current with no power loss) along with a diode to ground (anode) to provide a path for the negative capacitor current.
In that case both optos would be on for an AC input, but only the resistor coupled one for DC.

LST

Joined Jan 17, 2020
12
Thank you AlbertHall for offering to incorporate my design with yours. Mine isn't much of anything and can be completely scraped for something that better incorporates into yours. Thanks again.

Resister is a 1W 68K, diodes are IN4005.

AlbertHall

Joined Jun 4, 2014
10,068
You just need to connect both left side of your circuit and the left side of my circuit to power supply line and the right hand side of the two circuits to two pins of the micro.