Author Topic: Universal voltage input for 5v logic  (Read 1766 times)

0 Members and 1 Guest are viewing this topic.

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Universal voltage input for 5v logic
« on: January 14, 2024, 08:18:32 pm »
My question is, what is the cheapest, safest way to have a wide input voltage range feed into a logic level circuit.
Expected input responce will be less than 5hz, but i want to be able to handle 240v mains to see if a genie pops out

After playing in the stimulator with a few different options I wanted to ask here before I waste smoke.
The circuit below takes an ac or dc(with correct polarity) signal, enters into a half bridge rectifier.
R1 provides current limiting into a zener diode to limit the maximum voltage.
C1 was added to help stability with ac signals
R3 discharges C1 when the input signal is removed and helps reduce false triggering.
A generic n-type mosfet powers an optocoupler connected to a battery powered scope

Built on the breadboard with the values listed below, everything worked as expected at up to 36DC and 24VAC. I have not tried higher voltages yet
All these parts where on hand.
D1 - 1N5408l
R1 - 2 × 1meg + 500K 1/8w
D2 - 5.1 zener unknown part number
C1 - i measured at 9.99nF, small ceramic cap, mayby 12v. Dont know for sure
R2 - 10 × 1meg 1/8w
Q1 - IRF510

Before i drop mains onto this i will etch and drill a pcb with wide spacing
https://everycircuit.com/circuit/4635868824076288
« Last Edit: January 15, 2024, 12:14:52 am by Rainwater »
"You can't do that" - challenge accepted
 

Offline MarkT

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: gb
Re: Universal voltage input for 5v logic
« Reply #1 on: January 14, 2024, 10:18:42 pm »
Depends how fast.  Opto-coupler could be good - use current limiter diode for the emitter, rectifier if you want (or just an opto with anti-parallel emitters).
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #2 on: January 15, 2024, 12:45:09 am »
So the pcb does not work at all. I think the breadboard had enough leakage currents to allow the circuit to work, without these parasitic the optocoupler does not work until I place a volt meter from the input ground to the 5v ground.
"You can't do that" - challenge accepted
 

Online Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1699
  • Country: ca
Re: Universal voltage input for 5v logic
« Reply #3 on: January 15, 2024, 12:57:24 am »
As designed, your circuit makes no sense to me.
What are you trying to do?
ie: Measure mains AC frequency? Voltage? etc?
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #4 on: January 15, 2024, 01:21:15 am »
I just want to known if the input is on or off. The input ranging from 5vdc ~ 480vac if you need a number on it.
If a voltage source is applied for "X" amount of time, turn the optocoupler on.

By bonding the grounds together, the circuit works. This means that each input will need an isolated 5v supply.

"You can't do that" - challenge accepted
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
Re: Universal voltage input for 5v logic
« Reply #5 on: January 15, 2024, 03:00:14 am »
Your main problem is likely to be the detection threshold.  A detection threshold appropriate for 5V logic will almost certainly be inappropriate for 480V AC or even 120V AC due to phantom voltages causing false detection.  If you load the circuit you are monitoring enough to reduce phantom voltages to sufficiently less than 2.5V peak that it doesn't trigger an input that can sense 5V logic levels, you will also have to handle the dissipation in that load when 480V AC is actually applied.

 
The following users thanked this post: tooki, Rainwater

Online Andy Chee

  • Super Contributor
  • ***
  • Posts: 1089
  • Country: au
Re: Universal voltage input for 5v logic
« Reply #6 on: January 15, 2024, 04:11:31 am »
I just want to known if the input is on or off. The input ranging from 5vdc ~ 480vac if you need a number on it.
If a voltage source is applied for "X" amount of time, turn the optocoupler on.
I would put the If-THEN-ELSE logic on the low voltage side of the optocoupler.

In other words, you will have two sections:

1) If input is on, optocoupler is on.  If input is off, optocoupler is off. (this happens on the high voltage isolated side)
2) If optocoupler is on for "X" amount of time, then transistor/mosfet output high, else output low. (this happens on the low voltage logic side, using an Arduino or 555 timer or whatever).

Don't try and simulate this circuit, it's meant to only be illustrative, not prescriptive.  If you are using mains AC only (i.e. no DC) then the 100k resistor could be replaced with a 47nF capacitor.

« Last Edit: January 15, 2024, 04:42:54 am by Andy Chee »
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4177
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Universal voltage input for 5v logic
« Reply #7 on: January 15, 2024, 07:43:46 am »
A passive current sinking digital input spanning 5vdc ~ 480vac is not possible.

You need to sink an amount of current to obtain a reliable detection, this is >2 mA (IEC 61131-2 Type 3)
For basically all voltage ranges. The impedance for 2mA at 230 a.c. is a lot higher than for 24 dc.
See 61131-2 table 8. (there are some copies around on the net)

An input doing 5vdc ~ 480vac would be a really bad input (noise sensitive), or a really expensive input (power loss).
 
The following users thanked this post: Rainwater

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #8 on: January 15, 2024, 10:25:12 am »
So the high input impedance is my limiting factor.
By avoiding large power dissipation by charging a capacitor and monitoring the voltage with a mofset i have created 2 conditions which the circuit simulation does not account for.
First is the parasitic ac coupling of my conductors
Second is the floating ground reference between two isolated voltage sources
Thank you for the IEC 61131-2 Type 3 reference
"You can't do that" - challenge accepted
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2504
  • Country: gb
  • Recovering Electrical Engineer
Re: Universal voltage input for 5v logic
« Reply #9 on: January 15, 2024, 08:48:57 pm »

You can use a 'bit crap' current source to drive an optocoupler- that'll give you some much needed isolation and help keep the reaper at bay.
A FWBR makes for a don't care input polarity. You could add a cap across the DC terminals. Try it out.
Filter and square up the output with a Schmitt trigger (a 555 would do nicely).
You need to use 2W for the 51k's (or 4x 1W 22k's) and npn's that can handle your peak input voltage. 400V parts are cheap.
R3 is a standard 1/4W type. A high gain optocoupler would be a good idea.
A MOV and a fuse on the input would go amiss.




 
The following users thanked this post: Rainwater

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #10 on: January 16, 2024, 12:58:11 am »
Never heard the phrase 'bit crap' before. But google kinda explaned it.
I like the idea of a full bridge, it removes the need for an additional voltage source on the input side of the circuit and the polarity issue. Pulling a few specs from the datasheet, it looks like "X2" starts conducting at 0.9v
At 240vac and 0.027 amps, thats about 6.5w going through the transistor or my maths are wrong.
.9v / 33ohms = 0.027A  27mA * 240vrms = 6.5w
Or do you apply the rms to that as well. Seams more intuitive that way.
So about 4.6w.
Having to load the circuit is wasting power and seriously complicating things.
A Heatsink is a must and ive had a lot of success with the isolated to-220 devices.
If i can keep the cost point and circuit size below that of a relay them im in the green.
Im looking at a IRFIBE30G n channel mosfet.

Yall correct me where im wrong here but with a mofset instead of a bjt, the pullup resistor attached to the gate/base can be oversized(ohms not wattage), simply limiting current into the zener. With a bjt it is nessacery to supply the base with a current => load current ÷ hfe resulting in the circuit under preforming at lower input voltages.
I need more experience with mosfet current limiters, right now im assuming they work exactly like a npn limiter but im sure there are differences that will get me smoke before this is over.
Thanks for all the help so far. Yall stay warm.

And in case your curious, my pcb rolled smoke at 85vac, i don't think that was a 1000v diode. All for the cause
"You can't do that" - challenge accepted
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2504
  • Country: gb
  • Recovering Electrical Engineer
Re: Universal voltage input for 5v logic
« Reply #11 on: January 16, 2024, 11:31:10 am »

I made an error with the pass transistor there. It needs to have some grunt so a power type would be needed. See my corrections.
Two diode drops is probably a bit too much for reliable detection of 5V DC. A single series diode is probably enough.
The big downside is that the LED current must come from the input voltage source.

A universal input is a big ask.

Another aproach is to amplify the potted down volts and use a high gain amp and let it get over driven- low pass, Schmitt trigger etc.
Some noise rejection can be applied with Cn
Tweak R3 for lower end threshold.



 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #12 on: January 16, 2024, 11:47:34 am »
Sorry, If it was easy i would not be asking.
I found a 1v foward voltage optocoupler but still getting issues at 5v.
In thinking of ditching driving the optocoupler via the input and instead using the current limiter to load the input and a comparator to detect when maximum current is reached.
I may have to relax my "stupid proff" requirements a little and depend on the end user to flip a dip switch. With that said i have to figure out. How to do this in such a way that an invalid configuration would only result in a smoke free condition.
"You can't do that" - challenge accepted
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #13 on: January 16, 2024, 06:48:15 pm »
The attached drawing is a little bit of a mess
Starting from the left are the test voltages sources (+5dc, 120ac, 480ac) full of confusing switches, next is a full bridge, feeding a power hungry mofset acting as a linear regulatory. Goes into a filter cap and a ~20ma current limiter load.
The voltage across the load resistor is monitored by a comparator and triggers the optocoupler.
1983070-0
https://everycircuit.com/circuit/4635868824076288

In sure the 1amp inrush at 480v will blow a real circuit to bits, haven't worked on limiting that yet.
But its showing 10.5w rms. Comparing this to 90va pulled by the relays i want to replace, im in the green, but now i need a heatsink.
1983076-1
« Last Edit: January 16, 2024, 07:08:50 pm by Rainwater »
"You can't do that" - challenge accepted
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #14 on: January 21, 2024, 12:53:19 am »
ROUND 2
1986985-0
https://everycircuit.com/circuit/6096588258410496

So my new failing approach, is almost everything i've dreamed of. Unable to find a high power p-channel mosfet thats reasonably priced/available. I tried doing a little simple math to generate a referance voltage that will control the "Load" circuit.
Starting from the bottom left are the same input circuits as before, once rectified, voltage enters into the "Load" circuit.

Power across the load transistor has been reduced by about half at the maximum input. My goal is to get it even lower. At higher voltages, the voltage divider can act as a passive load, consuming over a quarter watt rms at full scale, solving the phantom power issue. At lower voltages, the active load circuit consums the majority of the power.

Here is a perty chart of my current problem, see I am not good at doing math, i was thinking that if i reduce the current of the load, proportional to the input voltage, my problems would be solved. But as you can clearly see, current and power share a non-linear relationship that i forgot about.
1986979-1

2 days ago i started reading about a Gilbert cell circuit, them old timers where smart. Me, not so much, but smart enough to know that calculating the wattage and piping that into the adjustable load would be a great way to make a adjustable power souce out of my adjustable current source. Its one of those "So close yet so far away moments". I quickly abandoned that pathway and am currently looking for an easier way to reduce the current in any non-linear way.

Thinking about attacking the subtraction amps reference voltage, but i think that will produce a linear result as well.
« Last Edit: January 21, 2024, 01:18:03 am by Rainwater »
"You can't do that" - challenge accepted
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 8086
  • Country: ca
Re: Universal voltage input for 5v logic
« Reply #15 on: January 21, 2024, 06:51:55 am »
Have you considered an ultra-low current optocoupler.  They will operate below 0.1ma, but can still handle up to 20ma at the IR led input.  The only thing about them is that they are very slow.  Something like up to 100hz.

For example, use a 30k series resistor.  The opto should easily switch on starting at 5v.  And at 300v, the LED will only see 10ma while your series resistor will need to handle 5w just to be safe.

You can also break down the input voltage divider with 2 resistors and a Zener diode stage inbetween to allow a lower wattage resistor.
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22382
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Universal voltage input for 5v logic
« Reply #16 on: January 21, 2024, 08:16:59 am »
Not sure what that circuit is doing, or trying to do; the current paths are all over the place, and high voltages exposed to MOS gates will instantly turn them into slag.  It's not a sensible approach I'm afraid.

I would suggest something like a depletion MOS current limiter, as a more likely part of a solution.  Have a well-defined current flow path (part of having a reliable logic input state, is being able to draw some current from whatever the source is), set that current with such an element, then pass that current through some logic element that handles other aspects -- filtering and de-glitching, hysteresis, isolation, etc.  The above examples with optoisolators are a fine way to go: the current flow path is isolated to the input circuit and nothing else, and only a low capacitance is shared between that circuit and your main circuit.

The current flow remark is most explicit in control schemes like 4-20mA current loops, where the voltage is modest (typically 5-30V, but historical examples go up to 100V+ and 100mA or so -- back in the days of electromechanical teletype), but also includes modern industrial examples like AC control voltages (typically feeding relay coils, and electronic surrogates), and arguably even digital standards like LVDS or CANbus (current or voltage feeding a terminated bus), or even TTL logic (the inputs of which draw some current).

TTL is kind of an interesting example here, because the input current is designed to be more of a nuisance -- an acceptable compromise, moreso than a matter of confidence; but as it happens, many systems use default-high signals as a default, powered but inactive, state, asserting those signals only when low (hence all the active-low signals on your typical vintage CPU bus).  So what starts as a quirk of the logic family in use, can still be turned into a kind of confidence measure.

This doesn't apply to CMOS of course, where the inputs draw very little current indeed, and can float freely up or down; '0' or '1' are equally probable in an open-circuit condition, or in the presence of noise.  (Or, at least, equally probable given no further information about the devices themselves.  It may well be that CMOS inputs tend to drift high, or that input thresholds cluster towards the low end of the input voltage range, etc.  I don't actually know these offhand, I certainly haven't measured enough gates to have any feel for it.  Not that it's something you should be designing based upon, anyway. :) )

Anyway, regarding likely applications here, some input resistance or current draw is likely desirable, as otherwise-open-circuit or nominally-off AC lines, typically have some voltage on them regardless; whether because of solid-state switches or snubbers (some current leaks through the capacitance or leakage current), or because wiring is arranged in cables or raceways and capacitive coupling partially energizes the circuit, to the same end.  Whether such resistance should be always-present, or optional whether by jumper or switch on the device, or applied externally (a common domestic situation is, SSR-switched LED lights not going fully off, but instead charging up slowly until reaching the start threshold and flashing slowly -- the standard solution is to leave one incandescent light in the circuit so its resistance shorts out the leakage), that's a matter of system design and typical use.

In any case, a likely circuit might have, either an anti-series pair of depletion MOS to limit current on the AC side, or a FWB rectifier then a single DMOS to limit DC current following the rectifier, then feeding an opto-isolator, which can be bidirectional or unidirectional LED type (respectively), with phototransistor output most likely.  Output current can be measured, or sent into a pull-up resistor and the voltage measured, and digital filtering can be applied, as well as analog filtering at the input.  Transient protection is highly desirable as mains is a dirty environment; some (maximal) series resistance might be used to set minimum input voltage threshold and limit peak surge current simultaneously, and a small MOV can be employed to protect the DMOS.

A series resistor and shunt MOV also helps to extend the input voltage withstand (momentary or continuous), depending on ratings.  It's a blunt instrument however, so be careful calculating values and compromising between V_IH(min) vs. Vin(max).

Some RC or LC filtering may be desirable too, as even without the rectifier, DMOS have some rectifying effect, and RF on the line will cause a false positive reading.  (Note that MOVs have some capacitance, so the above already has some value in this respect.)  Some common-mode filtering with respect to the chassis (or other suitable ground reference) may also be desirable to mitigate interference into the optoisolator itself.  Probably, these would be important considerations in the 10s of V (or V/m) level of immunity testing, so might be relevant to industrial or heavy-duty applications, but wouldn't be necessary for commercial purposes (typically 3V / V/m immunity); I would still insist on the surge protection steps (as surge of 1-2kV is typical).

---

An even more general point, we should ask along these lines is: not only "what is the bit value?", but "how well do we know the bit value?" -- what confidence level, what likelihood of correctness, does that bit have?  Perhaps this level of consideration is rather over-the-top here (or trivial, i.e. a simple '1' or '0' suffices -- essentially, you need only a very low confidence level in the confidence level, you don't care whether it's a well-defined value or not, just as long as it *is* some value at any given point in time), but it's a level of nuance that becomes critical in the design of radio systems, where unreliable reception is not merely unavoidable but indeed an intended part of the design; and we can apply the same principle even if the signal is direct wired, as the wiring itself can be unreliable, or signal source (by circumstance of what happens to be wired up at any given time, or mis-wired as the case may be) can be inconsistent or unreliable, or interference can be strong enough to bring the reading into question.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #17 on: January 21, 2024, 10:59:55 am »
Not sure what that circuit is doing, or trying to do;
Im attemping to make an active load that will consume a consistent amount of power/watts across a voltage range.

A amount of power must be consumed in order to prevent false triggering caused by parasiticly coupled voltage sources.

The first attempt was using a fixed 20ma of current, which worked but caused large power dissipation across the loading transistor.

This circuit compares the voltage drop across a 150 resistor to a reference voltage that is dynamically generated.
The reference voltage is approximately equal to 3 - (input voltage × 0.00375) this results in a current draw that drops as the voltage increases.
1987315-0
This current drop limites the power dissipation of the loading transistor.

To determine wither the circuit is "on/off" is simply a matter of checking if the current limitor is active. Im assuming (have not tested) this condition should only be true when the circuit is loaded with the appropriate amount of voltage and current.
"You can't do that" - challenge accepted
 

Offline ejd.pol

  • Contributor
  • Posts: 41
  • Country: nl
Re: Universal voltage input for 5v logic
« Reply #18 on: January 21, 2024, 01:44:27 pm »
Hey, maybe the following is overkill or does not fit into the specs somehow.
Anyway, it may trigger ideas for some other solutions.

It seems your problem is actually twofold: a wide range input, and an isolation issue.
As far as the isolation issue goes, this might be helpful in some way:

https://www.ti.com/tool/TIDA-01230

There are similar devices for I2C, etc.

Kind regards, Evert-Jan
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Universal voltage input for 5v logic
« Reply #19 on: January 22, 2024, 05:16:39 pm »
Ive got it figured out how, now i need to know the how much.
Been taking measurements at work on different lines to different equipment.
And the variables in phantom voltage are actually perty interesting.
All the switches and buttons are identical parts, i also have the maintenance logs so I know how long each component has been in service.
Already noticing trends in parasitic voltages due to environmental differences of the equipment(humidity/temp/ how close to the door) and time in service.
The amount of power contained within these open circuits is the next issue. 5V 20ma = 0.1W as spec by the standard mention earlier.
<<rant>> who do i need to slap for writing an industrial standard for control equipment, and then trying to charge $600usd just so people can read it. ..|.. to that crew <<rant over>>
But from the test i've ran so far, mostly at 480vac and 360dc, the amount of power generated by capacitive and inductive coupling has been much less than 0.075W. Its hard to measure and readings are inconsistent.
Any research paper recommendations would be greatly appreciated.
But the non linear power draw ( or linear current draw, depending on where your standing) does seam to effectively dissipate these parasitics without falsely triggering the optocoupler.
My current mosfet is not rated at the proper voltage for me to turn it on, but when passing parasitic current, it holds its own due to the fast voltage drop of the open circuit.
Might turn it on just to get a bang
"You can't do that" - challenge accepted
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf