Isolating analog signal with an optocoupler? - Page 1
Forum section: electronics / projects

author: sgnka
author_rank: Contributor
timestamp: August 12, 2023, 04:36:22 pm
content: I have an AC signal (just mains voltage dropped down through a resistor chain) which I need to read on my microcontroller but it needs to be isolated. I'm aware there exist some analog optocouplers IL300 etc. but these are way too expensive for the BOM.How can this be done with a simple optocoupler like a PC817? Is there a way we can use the transistor within the 817 as a linear output commensurate with current through its LED?I've seen optocouplers used for isolated voltage feedback in flyback SMPS circuits along with a TL431. Can that concept be used here?Thanks.

author: macboy
author_rank: Super Contributor
timestamp: August 12, 2023, 04:50:14 pm
content: You could use a pair of optocouplers (LEDs in series) and an opamp. One opto will provide local feedback to the opamp in order to linearize the signal. The other will go to the isolated side. Unfortunately this requires power for the opamp on the non isolated side.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 12, 2023, 04:51:38 pm
content: You could use a tiny MCU with built in ADC and a simple dropper supply on the AC side, and then send the data digitally via an opto.EDIT: Or just buy an isolated amplifier chip for a few dollars:https://www.ti.com/lit/ds/symlink/amc1100.pdf

author: Kleinstein
author_rank: Super Contributor
timestamp: August 12, 2023, 04:57:51 pm
content: The LED part in optocouplers usually has quite some temperature dependence. The phototransistor is often also a bit nonlinear, though not very temperature sensitive. So the linear OK like the IL300 use 1 LED and 2 photodiodes to compensate for the LED effect. The photodiode parts is usually quite linear and only weakly temperature dependent (would also compensate).The obvious choice for the problem of reading an AC current with isolation is using a current transformer. For this one may reuse an toroidal inductor(especially current compensated type) and an added wire for the primary.

author: uer166
author_rank: Super Contributor
timestamp: August 12, 2023, 06:20:11 pm
content: Do you actually require galvanic isolation? Or do you need it to simply be safe.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 12, 2023, 07:56:39 pm
content: If you only need an on/off sense, or a few levels (nominal, over, brownout, 120/240...), a comparator (or similar effect by way of biasing the LED, or a few transistors, or an IC proper) can be wired on the mains side.Optos are useless even for gross accuracy signal coupling (>50% error) because the gain is so unreliable. Unless you use a linearized one like IL300, indeed (and even then, it's only within about 20% untrimmed).The preferred solution is a sigma-delta modulator on one side, logic isolator (can be opto, or inductive and capacitive monolithic solutions are common these days), filter (or other demodulator basically). Bandwidth is limited (it's basically a 1-bit ADC/DAC), though solutions up to a few 100 kHz are available. More, you might want a proper RF system instead, whether that's direct coupling via transformer (perhaps diplexing bands between a LF opto channel if needed) or modulated on a higher carrier (or lower for that matter; you can make an isolated chop amp, with some cleanup needed around Fsw of course).There's also the possibility of resistors, which, I forget what the actual rules are, if isolation only needs to be some resistance (megs --> ~uA maximum leakage), or there are additional requirements (galvanic path something or other?). They need to be rated for transient voltage at the very least (hi-pot and surge).Tim

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 12, 2023, 09:19:43 pm
content: Quote from: sgnka on August 12, 2023, 04:36:22 pmYes, but that is a single set point.QuoteYes, but the gain and temperature spreads are massive on opto-couplers.Since this is AC mains, why not simply create a precision zero cross circuit, and you measure the pulse width. (A low current version of TL431 can help here)Or, you can use a voltage detector + opto to create a current to pulse width generator and MCU looks for smallest pulse width.The pulse width gives you the amplitude of the sine wave.

author: Benta
author_rank: Super Contributor
timestamp: August 12, 2023, 09:32:37 pm
content: As the OP does not state what is to be measured, this is a guessing contest.Presence of AC?Voltage of AC?Waveshape of AC?etc., etc.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 12, 2023, 09:40:55 pm
content: Isolated from what? That's the first question.

author: Benta
author_rank: Super Contributor
timestamp: August 12, 2023, 09:55:25 pm
content: https://www.eevblog.com/forum/beginners/newbies-please-read-before-posting-24542/

author: Terry Bites
author_rank: Super Contributor
timestamp: August 12, 2023, 10:10:03 pm
content: Is your application sensing or measuring a signal or both?A small transformer is a simple and safe solution. It could even be a home brew CTR.If you go down the linear isolation route you need an iso power supply on the hot side. That can be very inconvenient.Consider using isolated ADCs and digital isolation, its chepaer to implement than a decent linear iso amp. (Last time buy on that front now).OMG. IL300s and their kin. Too far much addon circuitry and assorted power supplies for my liking!ACPL-7900 anyone. Hall or GMR current sense?

author: Tomorokoshi
author_rank: Super Contributor
timestamp: August 12, 2023, 10:12:44 pm
content: Quote from: sgnka on August 12, 2023, 04:36:22 pmIn addition to all the other comments and questions brought up here:1. Who set the requirements for isolated measurement of AC power line voltage?1. How necessary is it to the design?2. Which standards will apply to the design?2. Who set the requirements for the itemized BOM cost?1. What percentage of the target BOM is an IL300?3. How is engineering amortized across the production run?1. Is it worth it to design your own when you can buy a solution?2. Are you confident you can design your own within the schedule?

author: jonpaul
author_rank: Super Contributor
timestamp: August 13, 2023, 01:34:24 am
content: 1:1 120/240 isolation transforer for voltageCT for currentLow cost, passive exact ratios.Opts are inherenty non linear and CTR changes with time.Typical limits are +200% -50% CTRJon

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 13, 2023, 03:08:15 am
content: Quote from: Kim Christensen on August 12, 2023, 04:51:38 pmWith the low prices of small MCUs that's a valid idea, but it needs care to pick a small MCU that can start from low energy, or a small MCU plus a power pulse scheme.Nuvoton have released a MCU that is designed for energy harvesting type power, with a spec'd 200uA max startup.https://www.nuvoton.com/products/microcontrollers/8bit-8051-mcus/low-power-mug51-series/

author: schmitt trigger
author_rank: Super Contributor
timestamp: August 13, 2023, 03:45:51 am
content: Some times the simplest is the optimal solution.Like someone already mentioned, a small steel core transformer, 230/115 volts primary and 6.3 volts secondary, which should be completely unloaded, save for the resistor divider to accommodate the microcontroller’s input range.It will have a couple of degrees of phase error, which should be of no consequence if only the voltage’s magnitude is to be measured.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 13, 2023, 06:09:49 am
content: Quote from: schmitt trigger on August 13, 2023, 03:45:51 am'Simplest' is relative.Yes, it is 'one component', but what a heavy, bulky, expensive and non-automation friendly 'single part' that steel core transformer is !In contrast, SMD opto couplers start from about 2c/200+ at lcsc, and can be pick and placed.

author: gnuarm
author_rank: Super Contributor
timestamp: August 13, 2023, 07:06:37 am
content: Quote from: PCB.Wiz on August 13, 2023, 06:09:49 amBut they don't provide much more than on/off type of information.As others have pointed out, the problem is not well specified. I don't see where the OP has returned to provide any more information. But, his original post does ask or a "linear" response. That's what Sherlock Holmes calls a clue.As many others have said, it is hard to get a linear response through an optocoupler... very hard. But in many cases, the resistor chain he is currently using can be adequate. If the requirement is for safety, the resistor chain can use a very large resistor to provide adequate isolation. If that drops the voltage too much, an op amp can be used to restore the proper value to match the ADC. But there's many a slip between cup and lip. Much more info is required.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 13, 2023, 07:12:08 am
content: Optocopuplers have bad current transfer linearity, i.e. don't expect to have the double at the output when supplying 2x current to the led.If you require precision either - A transfer digital pulses (You'll need a fast optocopupler) or B - Use anisolated op-amp.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 13, 2023, 07:18:58 am
content: Quote from: gnuarm on August 13, 2023, 07:06:37 amOf course, that's why I suggested a pulsed approach, simple parts can take the voltage and deliver a pulse thru the optocoupler.The OP did not say if they wanted Zero-Crossandvoltage measurement, so I've focused on voltage measurement.

author: Smokey
author_rank: Super Contributor
timestamp: August 13, 2023, 07:30:47 am
content: Isolation Amplifier?https://www.analog.com/en/parametricsearch/11062#/

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 13, 2023, 11:14:18 am
content: A problem with opto isolators is that their transfer characteristic is not very lineair, and it may also drift a lot with temperature.The power supplies with TL431 and an opto solve this by not providing a direct feedback of the output voltage, but they feed back a digital signal of the time when the TL431 has detected an output voltage that is high enough.And you can do something similar. Voltage to frequency converters were quite common at some time, and you can also make a voltage to PWM duty cycle by comparing the analog voltage with a triangle waveform. But all these solutions require a fair bit of extra circuitry. In these modern times it makes more sense to just uses some microcontroller with ADC and then send some uart signal through an optocoupler (uart only needs one optocoupler)There are also "standard solution" for galvanic isolation of I2C. It's more complicated, but also more integrated into some IC so the complication does not have to bother you so much.And of course you can also just buy the whole thing. Signal isolators are quite common in industrial applications and you can buy readily made modules inclusive a housing that fits on a DIN rail and screw connectors, and from Ali / Ebay they are not very expensive.

author: sgnka
author_rank: Contributor
timestamp: August 14, 2023, 07:44:45 pm
content: My apologies, guys. I've been away for a bit, and I see that my post left out key info.Yes - the requirement is to get the voltage of the AC mains but on the secondary side of the optocoupler.It doesn't have to be super accurate, so I think I'll go with measuring the width of the pulse on the secondary side of the opto and try estimating the amplitude.Thanks!

author: uer166
author_rank: Super Contributor
timestamp: August 14, 2023, 09:11:39 pm
content: I'll ask again, do you need galvanic isolation or not? If you are okay tying your MCU reference to protective earth, just use appropriately sized resistor dividers from the mains to your MCU. That can be considered reinforced isolation in the safety context.You have to watch for max allowed leakage and number of resistors (something like 5-8 1206 packages at 1.6MOhm is what I use). It is simultaneously the simplest, cheapest, and depending on ADC the most accurate solution. The only downside is having to reference your MCU to protective earth, but that happens automatically anyway if you connect your MCU to a PC for example.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 14, 2023, 10:22:03 pm
content: Quote from: sgnka on August 14, 2023, 07:44:45 pmThat's what I understood.See attached simple dual-slope voltage to pulse opto design, that gives zero cross and mains voltage in pulse width.CAP charges to voltage determined by mains, and discharges at somewhat regulated ~500uA so dT is proportional to mains voltage.Precision is determined by the current accuracy : mains resistors ratios.C1 value is less critical, but don't use something terrible. Start with a film capacitor.addit : Possibly something like GRM31C5C1H104JA01LCOG100nF 50V 5% 1206 1.8mmT ~7c/500 at lcscPSSI2021SAY claims typ 0.15 %/K, not sure I believe that ? (0.3% is more typical)You may want to test some variants, if temperature stability is important, or measure temperature in your MCU and do some simple correction ?

author: uer166
author_rank: Super Contributor
timestamp: August 15, 2023, 12:01:02 am
content: Quote from: PCB.Wiz on August 13, 2023, 06:09:49 amThat's why you don't use avoltagetransformer to measure mains voltage. By requiring full mains on the primary the volt-second requirement pushes the size up. You can't measure voltage directly with an opto without bending over backwards with S-D modulation etc.. If you need galvanic isolation use acurrent transformerinstead, such ashttps://www.lcsc.com/product-detail/Current-Transformers_ZHE-MING-LANG-XI-ZMPT107-1_C125191.htmldesigned specifically to measure mains voltage. You have to do a voltage->current conversion via a resistor chain, pass that through CT, and convert the current back to voltage via a burden resistance. This is pretty accurate and cheap (33 cents for linked part).

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 15, 2023, 01:28:56 pm
content: Have you ever looked into those power metering IC's? They measure(RMS) voltages and current, calculate power and push it through an isolation barrier i a way that is easily readable by an uC.