Universal voltage input for 5v logic - Page 1
Forum section: electronics / beginners

author: Rainwater
author_rank: Regular Contributor
timestamp: January 14, 2024, 08:18:32 pm
content: 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 outAfter 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 signalsR3 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 scopeBuilt on the breadboard with the values listed below, everything worked as expected at up to 36DC and 24VAC. I have not tried higher voltages yetAll these parts where on hand.D1 - 1N5408lR1 - 2 × 1meg + 500K 1/8wD2 - 5.1 zener unknown part numberC1 - i measured at 9.99nF, small ceramic cap, mayby 12v. Dont know for sureR2 - 10 × 1meg 1/8wQ1 - IRF510Before i drop mains onto this i will etch and drill a pcb with wide spacinghttps://everycircuit.com/circuit/4635868824076288

author: MarkT
author_rank: Frequent Contributor
timestamp: January 14, 2024, 10:18:42 pm
content: 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).

author: Rainwater
author_rank: Regular Contributor
timestamp: January 15, 2024, 12:45:09 am
content: 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.

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 15, 2024, 12:57:24 am
content: As designed, your circuit makes no sense to me.What are you trying to do?ie: Measure mains AC frequency? Voltage? etc?

author: Rainwater
author_rank: Regular Contributor
timestamp: January 15, 2024, 01:21:15 am
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: January 15, 2024, 03:00:14 am
content: 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 tophantom voltagescausing 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.

author: Andy Chee
author_rank: Super Contributor
timestamp: January 15, 2024, 04:11:31 am
content: Quote from: Rainwater on January 15, 2024, 01:21:15 amI 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.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 15, 2024, 07:43:46 am
content: Apassivecurrent 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).

author: Rainwater
author_rank: Regular Contributor
timestamp: January 15, 2024, 10:25:12 am
content: 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 conductorsSecond is the floating ground reference between two isolated voltage sourcesThank you for the IEC 61131-2 Type 3 reference

author: Terry Bites
author_rank: Super Contributor
timestamp: January 15, 2024, 08:48:57 pm
content: 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.

author: Rainwater
author_rank: Regular Contributor
timestamp: January 16, 2024, 12:58:11 am
content: 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.9vAt 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.5wOr 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 ÷ hferesulting 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 thatwasa 1000v diode. All for the cause

author: Terry Bites
author_rank: Super Contributor
timestamp: January 16, 2024, 11:31:10 am
content: 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 CnTweak R3 for lower end threshold.

author: Rainwater
author_rank: Regular Contributor
timestamp: January 16, 2024, 11:47:34 am
content: 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.

author: Rainwater
author_rank: Regular Contributor
timestamp: January 16, 2024, 06:48:15 pm
content: The attached drawing is a little bit of a messStarting 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.https://everycircuit.com/circuit/4635868824076288In 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.

author: Rainwater
author_rank: Regular Contributor
timestamp: January 21, 2024, 12:53:19 am
content: ROUND 2https://everycircuit.com/circuit/6096588258410496So 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.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.

author: BrianHG
author_rank: Super Contributor
timestamp: January 21, 2024, 06:51:55 am
content: 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.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 21, 2024, 08:16:59 am
content: 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 levelin 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

author: Rainwater
author_rank: Regular Contributor
timestamp: January 21, 2024, 10:59:55 am
content: Quote from: T3sl4co1l on January 21, 2024, 08:16:59 amIm 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.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.

author: ejd.pol
author_rank: Contributor
timestamp: January 21, 2024, 01:44:27 pm
content: 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-01230There are similar devices for I2C, etc.Kind regards, Evert-Jan

author: Rainwater
author_rank: Regular Contributor
timestamp: January 22, 2024, 05:16:39 pm
content: 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