ra3xdh / qucs_s

Qucs-S is a circuit simulation program with Qt-based GUI
https://ra3xdh.github.io/
GNU General Public License v2.0
879 stars 115 forks source link

Opto-Coupler, Isolator, Triac Library #213

Closed tomhajjar closed 1 year ago

tomhajjar commented 1 year ago

I'm working on a new Opto-Coupler, Opto-Isolator and Opto-Triac Library but I'm having problems getting Spice models that work under LTspice to work under ngspice.

The first device I'm working on is a Photovoltaic Isolator or PVI. They have been around for decades with modern versions having much faster response time. The most popular device is an Infineon PVI5050N. Unfortunately the factory model is unavailable and my attempts at creating a fully working version have failed.

My next choices are the Vishay VOM1271 and Avago ACPL-K30T.

VOM1271.cir created by the late LTspice contributor Jim Thompson, has been extensively tested under LTspice.

VOM1271.cir doesn't work under ngspice even using LTspice compatibility mode.

Vishay supplied VOM1271T.cir doesn't work for LTspice or ngspice.

Avago supplied ACPL-K30T.cir works under LTspice but give erroneous data under ngspice using LTspice compatibility mode.

VOM1271_TRAN_Thompson

VOM1271_DC_Thompson

ACPL-K30T_DC

ACPL-K30T_TRAN

ACPL-K30T_DC_Qucs

ACPL-K30T_TRAN_Qucs

Photo_Voltaic_Isolators_prj.zip

tomhajjar commented 1 year ago

OnSemi MOC3043M Opto Triac works in LTspice but not ngspice.

Vishay BRT22M Opto Triac seems to work in both LTspice and ngspice using LTspice compatibility mode.

MOC3043M_trigger_qucs

MOC3043M_trigger

BRT22H_trigger_Qucs

BRT22H_trigger

Photo Triacs_prj.zip

ra3xdh commented 1 year ago

Avago supplied ACPL-K30T.cir works under LTspice but give erroneous data under ngspice using LTspice compatibility mode.

The optocoupler model contains diodes and BJTs with the default model. I suspect that the default model for diode and NPN may be different for LTSpice and Ngspice. I didn't find the LTSpice specific constructions in the netlist expect the default models. This would explain the difference in the simulation result.

I mean the following lines by default model:

.model D D

.model NPN NPN
.model PNP PNP
ra3xdh commented 1 year ago

OnSemi MOC3043M Opto Triac works in LTspice but not ngspice

It seems the LTSpice compatibility mode in Ngspice is not fully implemented. At first I corrected subcircuit to use SpiceFile device instead of SpiceLibComp. The output of the Ngspice became more verbose. It reports error in the IF statement in the netlists and doesn't accept VSWITCH model. After I set ngbehavior=ltpsa the schematic starts to work, but the result is wrong. I suspect this model requires to be rewritten to work with Nsgpce.

tomhajjar commented 1 year ago

I ran into an issue with the BRT22x Opto Triac simulations. I found a typo in BRT22H.sch. It points to the model BRT22M.cir. When I renamed it to BRT22M.sch, the simulation fails. I then made a "fresh" BRT22H.sch also pointing to the wrong model BRT22M.cir and it fails. I made BRT22H.sch pointing to BRT22H.cir and it fails. I tried every combination of making fresh schematics and I could not get the simulations to work. I compared all models and schematics with a file comparison tool and cannot find anything that would cause issues. Only the original files BRT22H.sch and BRT22H_TRAN.sch I sent yesterday "work". I had to download the original files from this site since I over wrote them.

As a side note, the BRT22x.lib spice models have 6 pins with two unused pins having the same name, "NC". They also have two "dummy" components C1 and R4 connected to NC and 0. Qucs/ngspice wouldn't work unless I depleted the two "NC" pins. I named the models BRT22x.cir. I left the C1 and R4 lines alone. The modified models worked in LTspice.

.SUBCKT BRT22M A C NC MT2 NC MT1 X1 MT2 GATE MT1 BRT22M_tr D1 10 C Demit V3 11 10 0Vdc R3 A 11 1u TC=0,0 R4 0 NC 1MEG C1 0 NC 1u

BRT22H_sch

BRT22H_trigger_Qucs

BRT22M_sch

BRT22M_trigger_Qucs

BRT22x_prj.zip

tomhajjar commented 1 year ago

Vadim

Can you confirm if the issue above is a bug?

ra3xdh commented 1 year ago

The problem with NC node is not a bug. It is a floating node that has no current and may cause a convergence issue with Ngspice. LTspice may automatically add parasitic from floating node to the ground, but Ngspice has no such feature.

Regarding the problem with path to the model file I cannot reproduce this issue. Probably there is something related to the relative search paths.

tomhajjar commented 1 year ago

I confirmed there is something wrong. See "Qucs_netlist_logs.zip" (files renamed for clarity).

BRT22H_TRAN_netlist.cir works via Qucs BRT22M_TRAN_netlist.cir fails via Qucs

Both netlists work if I use DuSpice as the GUI instead of Qucs.

Qucs is generating both netlists properly but "corrupts" BRT22M_TRAN_netlist.cir when passing it to ngspice.

Below is the DuSpice plot using a modified version of BRT22M_TRAN_netlist.cir. The original netlist also works but only generates a text file.

I wonder how many other simulations have failed due to this issue.

BRT22M_TRAN_netlist

Qucs_netlist_logs.zip

ngspice_data_logs.zip

tomhajjar commented 1 year ago

I've given up on the OnSemi MOC3043M LTspice model.

An OnSemi MOC3082M LTspice model from the same source (https://groups.io/g/LTspice) seems to work OK.

MOC3082M_TRAN sch

MOC3082M_Opto_Triac.zip

ra3xdh commented 1 year ago

I've given up on the OnSemi MOC3043M LTspice model.

I have pointed above that LTSpice compatibility mode is not 100% LTSpice compatible. The most probably the problem is in default diode model that is used by MOC3043. It's unknown which parameters has the default diode and NPN devices in LTspice. By default model I mean the following usage .MODEL D D I am busy with Qt6 porting now. I will probably debug the MOC3043 model later. Please wait.

tomhajjar commented 1 year ago

First cut at an NPN output opto-isolator.

4N25.cir is a model from the 90s and seems to work OK. More complicated than ones from LTspice.

4N35.cir from Vishay using my mods is not working. 4N35.lib is original.

4N25-35.zip

ra3xdh commented 1 year ago

4N35 model contains table-dependent source that is not supported by Ngspice. It is unclear how to modify it.

tomhajjar commented 1 year ago

4N25 is probably good enough. Main difference is CTR.

None of the models include the output NPN Base connection. It used to be popular to use this connection, but not so much anymore. The vast majority of devices have no pin connected to the Base.

tomhajjar commented 1 year ago

I found another Opto Isolator that uses the same model "architecture" that many in the LTspice forum use, MOC207. It also provides a Base connection. The model line "G1 3 5 N003 2 0.724m" sets the CTR and is the only difference between devices.

I also redid ALL the schematic symbols since I accidently mixed blue and black colors.

MOC207

Opto_Isolators_prj.zip

tomhajjar commented 1 year ago

Finally have a working Photovoltaic Isolator (PVI) model, the Avago ACPL-K30T. Guys at ngspice came up with a fix.

They are making changes to ngspice so the modifications to ACPL-K30T.cir and ACPLK30T.cir ultimately won't be required.

ACPL-K30T.cir requires ngbehavior=ltpsa.

ACPLK30T.cir will work without ngbehavior=ltpsa.

https://sourceforge.net/p/ngspice/discussion/120973/thread/8c874eb3ec/

The ngspice transient response data doesn't exactly match LTspice but it should be good enough. More changes to the subcircuit would be required and it's doubtful it would get done. Without real test data, it's hard to say if the LTspice data is 100% anyway.

ACPLK30T_DC

ACPLK30T_TRAN

ACPLK30T_TRAN_LTspice

ACPL-K30T_PVI.zip

tomhajjar commented 1 year ago

I redid a number of components in the Opto Isolators project.

4N25 and MOC207 NPN Optocouplers. MOC207 also models the base connection which is desirable. Neither require ngbehavior=ltps

BRT22H/M and MOC3082 Opto-Triacs. MOC3082 does not require ngbehavior=ltps

It would be good to document that "in general", the subcircuit.sch file name should not be the same as the subcircuit.cir file name. In some cases (I cannot explain why) ngspice generates odd error messages, making one think the netlist or subcircuit has a problem. If I send the same netlist created by Qucs-S to ngspice using DuSpice, the netlist works. Very confusing....

Opto_Isolators_prj.zip

ra3xdh commented 1 year ago

I have added Optocoupler.lib library by the recent commit. This library will be available since the next release.

ra3xdh commented 1 year ago

TRIACs and optothyristors need to be modified to ensure compatibility with Ngspice. Every occurrence of the IF statement should be replaced by ternary operator. This will allow to use the library without the need to set the compatibility options for Ngspice.

ra3xdh commented 1 year ago

Help is appreciated for this issue and #212. The C++ knowledge is not needed to modify the models.

tomhajjar commented 1 year ago

On 2/15/23, you modified a MOC3082 Opto Triac Spice model done by Helmut Sennewald. Is it usable to make into a library device?

2023-10-24_211821 2023-10-24_211729 2023-10-24_211806

MOC3022_Opto_Triac_prj.zip

tomhajjar commented 1 year ago

I dug up some old SCR and Triac Thyristor models that might be usable. I haven't confirmed they work...

Thyristor.zip

ra3xdh commented 1 year ago

On 2/15/23, you modified a MOC3082 Opto Triac Spice model done by Helmut Sennewald

Yes, I will add this device ti the library.

I dug up some old SCR and Triac Thyristor models that might be usable

I have checked the SPICE sources and found that these models don't contain LTspice/PSpice specific definitions. It could be accepted for Qucs-S library.

ra3xdh commented 1 year ago

I have added MOC3082 model. The new Optocoupler.lib library will be available since the next version. Thyristor library will be provided in #212. Closing this ticket as completed.

tomhajjar commented 1 year ago

Is the ACPLK30T Photovoltaic Isolator usable in the optocoupler library? I realize I sent confusing and cluttered messages and files for this device. The device was modified by the ngspice guys to be compatible.

2023-10-26_112133 2023-10-26_112153

Photo_Voltaic_Isolator_prj.zip

ra3xdh commented 1 year ago

I didn't include the ACPLK30T device. I will add it on the next library update.

tomhajjar commented 11 months ago

Just confirming that the ACPLK30T Photo Voltaic Isolator will make it into the next release. It can be included in Optocoupler.lib if you don't want to make another library.

tomhajjar commented 8 months ago

Confirming that the ACPL_K30T Photo Voltaic Isolator will make it into the next release. It can be included in Optocoupler.lib if you don't want to make another library.

I tested it recently in Trainline_Driver.sch. It needs a resistor load in the MegOhm range

ACPL-K30T_PVI.zip