ra3xdh / qucs_s

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

Transformer library model test schematic fails simulation #231

Closed tomhajjar closed 1 year ago

tomhajjar commented 1 year ago

The Full_wave.sch schematic in the TranLibTest.qucs archive done by Mike Brinson has something wrong with it. All the other schematics seem OK. I made a copy of the original file and data and renamed it to "Full_wave_orig" to preserve it. You can see Mike's original data below. I cannot vouch for the accuracy of the data . The turns ratios for TRAN1 looks odd and i(vprd1) looks too low.

When you FIRST open Full_wave.sch, you will see Mike's original data.

Run a simulation, and the simulation time is truncated to .02 sec as shown in the second jpg.

Do a "Set on Grid" for R5 and simulation "works" and simulation time is like in Mike's original data.

Do a "Set on Grid" for D1 and the simulation time is truncated. Next do a "Set on Grid" for D2 and the simulation "works"

Do a "Set on Grid" for TRAN1 and simulation time is truncated.

This made me think the schematic was off the grid, incompatible model or there is a bad character in the file but it doesn't seem to be.

I redid the entire schematic and replaced the diodes and simulation time is still truncated.

The transformers symbols are not symmetrical. This isn't a problem except for the primary leads for the two center tapped transformers. They are not in-line as shown below. It could cause confusion.

Transformer library test

Transformer library test 2

2023-02-22_204353

Test_prj.zip

ra3xdh commented 1 year ago

This schematic works as expected using Ngspice-27. But doesn't produce a correct result using the latest Nsgpice-39. I suspect something has been changed in Ngspice or XSPICE since the library release. The Transformers library need to be fixed to provide compatibility with the latest Ngspice.

tomhajjar commented 1 year ago

I'm trying to identify all the issues with the XSPICEPS1S2 transformer in the library. As stated before, the model lacks the ability to change L or A and it's output polarity is inverted. I decided to recreate the original XSPICEPS1S2 subcircuit as shown in both the online help and Mike Brinson's 2016 paper. The goal is to fix all the issues.

I can get XSPICEPS1S2 from the library to simulate as shown in XSPICEPS1S2_lib_test.sch.

I cannot get the subcircuit I made, XSPICEPS1S2_sub.sch to simulate in XSPICEPS1S2_sub_test.sch. Maybe you can spot an obvious mistake.

As a side note, the Library view of the Cores library has issues. A spurious graphic {-} is displayed.

Trans_Core_1P_2S

2023-03-03_144622

2023-03-03_140235

Transformer_sub_Test_prj.zip

ra3xdh commented 1 year ago

I made some investigations on the full-wave rectifier circuit using XSPICE transformer. It seems there is something wrong inside XSPICE magnetic core model itself. It may operate correctly only if sinusoidal voltage applied to it. The summary is the following:

Maybe you can spot an obvious mistake.

The first line of ICOUPLE devices should be model name. It is SIcouple on attached screenshot. image

tomhajjar commented 1 year ago

Isn't "SIcouple" and acceptable name? The examples I see online aren't much different.

I decided to recreate the Library transformer model XSPICEPS1S1 as shown in the online Help. It use one Core entry.

To aid in testing I found an old KiCad (ngspice) netlist using core and lcouple, Trans_Xspice.cir. It is based on the example in the ngspice manual and uses the B/H data for an "iron-core". It is also the same example in the Altium manual.

I modified it and used DuSpice/ngspice. Analysis shows the output inverted (output pins 3/4 flipped?) The core parameters L =0.01 and A = 1 seem unrealistic but making L=1 and A=0.01 caused input/output voltages to be almost zero. The example in the ngspice manual uses L=0.01 and A=0.01 which also seems unrealistic. L=0.01 and A=0.01 cause noticeable distortion of the input and output voltages. Would need to calculate B and H to see if the core is in saturation.

I entered the circuit Trans_Xspice.cir into Qucs-S, 1P1S_XSpice_tran_test.sch. Unfortunately I'm having issues using the XSPICE "core" Component. I cannot figure out how to enter the core data from Trans_Xspice.cir into the XSPICE core block. Every variation I tried cause ngspice errors so I ended up using the Cores Library model "SheetSteel". Again the data is inverted and I cannot vouch for the accuracy. (See my comments below. Qucs-S is formatting the Spice netlist entries for "Core" wrong.)

Once I know how to use the XSPICE "core" Component, I can use transformer core data from a known good analysis.

Trans_Xspice_KiCad

L =0.01 and A = 1 Trans_Xspice_ngspice

L=0.01 and A=0.01 2023-03-05_192344

1P1S_XSpice_tran_test

XSPICE core block

2023-03-05_183402

Trans_Xspice.zip

tomhajjar commented 1 year ago

I created 3 netlists for use with DuSpice/ngspice to figure out what's going on. I believe Qucs-S is formatting the netlist entry for the generic Core model from Components wrong.

Trans_Xspice.cir is the test netlist I found on the web. I modified it to plot only in and out. It simulates without error. Data accuracy unknown.

The following two netlists are generated by 1P1S_XSpice_tran_test.sch.

Trans_1p1s_lib_netlist.cir, uses SheetSteel from the Core Library. Trans_1p1s_lib_netlist.cir - Simulates without error. Data accuracy unknown.

Trans_1p1s_comp_netlist.cir uses the generic Core model from Components, Core. Trans_1p1s_comp_netlist.cir - Fails to simulate.

The "ACORE" entry in Trans_1p1s_comp_netlist.cir is missing multiple items like .model ACORE2 core ( ........). Also missing are mode=1 but I believe that is the default for the PWL core.

Qucs_netlists.zip

tomhajjar commented 1 year ago

A minor issue is the name and prefix used for the "lcouple". Unfortunately the Forum font uses the same character for Small "L" and Capital "i"

Small "L" = l Capital "i" = I

In Components -> XSPICES devices, the lcouple is named "EYE"couple and the prefix is "EYE"COUPLE.

The source files are Icouple.cpp and Icouple.h. Meaning capital "i".

The files should be Lcouple not Icouple. This is confusing for users.

Some XSpice transformer info from the web. The Aylward paper mentions that using lcouple-core-lcouple results in the inversion of the transformer output signal which can be fixed by swapping output pins.

XSpice Cores Transformers.zip

__

tomhajjar commented 1 year ago

Until the XSPICE devices Component's Core code for generation netlist entries is fixed I cannot recreate and confirm the accuracy of Mike Brinson's 2015 data. The "Core" netlist parameters and data structure is wrong.

Schematic using generic Core from XSPICE devices 2023-03-14_182208

Netlist using generic Core from XSPICE devices - BAD 2023-03-14_182223

Schematic using Sheet Steel from Core Library 2023-03-14_183335

Netlist using Sheet Steel from Core Library - GOOD 2023-03-14_183320

1P1S_XSpice.zip

ra3xdh commented 1 year ago

The "Core" netlist parameters and data structure is wrong

Ngspice should accept both modelcard card syntax. Both space separated parameters and using parentheses should be allowed. Something may have changed here between Ngspice-27 and the latest Nsgpice.

tomhajjar commented 1 year ago

There is a lot of differences between the "core" netlist entries used in KiCad/ngspice manual example and what Qucs-S generated.

Disregard the missing "(" ")" ".model" "(" and ")" from the netlist.

Qucs-S is combining the separate "a" and ".model" netlist entries into a single entry called "ACORE2". I cannot find any ngspice or XSpice document or examples that says this is OK.


KiCad/ngspice example netlist Trans_Xspice.cir:

a3 (interNode_1 interNode_2) u1_iron_core .model u1_iron_core core (H_array = [-1000 -500 -375 -250 -188 -125 -63 0 63 125 188 250 375 500 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3 -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3] area = 0.01 length = 0.01)


Qucs-S generated netlist for Trans_1p1s_comp_netlist.cir:

ACORE2 n1 n2 Length = 1 Area = 0.01 H_array = [-1000 -500 -375 -250 -188 -125 -63 0 63 125 188 250 375 500 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3 -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3]

Qucs_XSpice_Trans_netlists.zip

tomhajjar commented 1 year ago

Last comment:

Only the Core parameters for H. B, A and L are different for 1P1S_XSpice_test.sch and 1P1S_XSpice_Core.sch. The netlist structures should be the same but 1P1S_XSpice_test.cir and 1P1S_XSpice_Core.cir look NOTHING alike.

1P1S_XSpice_test.cir uses ".SUBCKT Cores_SheetSteel"

1P1S_XSpice_Core.cir is missing the .SUBCKT entry

1P1S_XSpice.zip

tomhajjar commented 1 year ago

Until Components...XSPICE...core device is fixed, if you need a Core different than in Cores.lib or used in Transformers.lib the only choice is to use a Text Editor and alter the B, H, L and A parameters manually in the .sch file.

XSPICEPS1 and XSPICEPS1S2 need A and L added. Info on Core material would be useful.

XSPICEPS1S2 output is inverted so output nodes need to be swapped. Info on Core material would be useful.

Strangely XSPICEPS1, XSPICEPS1S2, LossyTransformer1 or LossyTransformer2 don't use any of the B/H parameters in Libraries...Cores. I'm unsure where any of the B/H data in Transformer.lib and Core.lib came from. All the more reason to get XSPICE...core working.

I tested using lcouple and Sheet Steel Core to make a non-linear inductor. AFAIK it works.

2023-03-22_204548

2023-03-22_204612

Qucs-S.zip

ra3xdh commented 1 year ago

I have tested the provided schematic again. The problem is that you are using the system CORE device wrong. There is not bugs in netlist generator. The attached example shows how to define core model using this device. image

ra3xdh commented 1 year ago

Here is the schematic file.

Core.zip

tomhajjar commented 1 year ago

I confirmed that the changes to Transformers.lib work however XSPICEPS1S2 still has an inverted output. Attached is the fixed Transformers.lib.

See my comments in #228

Transformers.zip

ra3xdh commented 1 year ago

I have fixed polarity issue of the XSPICEPS1PS2 device. I have also found modelcard issue that may cause incorrect simulation. See the latest version here: https://raw.githubusercontent.com/ra3xdh/qucs_s/current/library/Transformers.lib

tomhajjar commented 1 year ago

I recreated all the Mike Brinson transformer models in the online help. This folder may be useful for someone.

Transformer_sub_Test_prj.zip

ra3xdh commented 1 year ago

Closing this as resolved.