Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformer library model test schematic fails simulation #231

Closed
tomhajjar opened this issue Feb 23, 2023 · 17 comments
Closed

Transformer library model test schematic fails simulation #231

tomhajjar opened this issue Feb 23, 2023 · 17 comments
Assignees
Milestone

Comments

@tomhajjar
Copy link

tomhajjar commented Feb 23, 2023

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

@tomhajjar tomhajjar changed the title Mike Brinson transformer library model test schematic fails simulation Transformer library model test schematic fails simulation Feb 23, 2023
@ra3xdh
Copy link
Owner

ra3xdh commented Feb 23, 2023

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.

@ra3xdh ra3xdh added this to the 1.0.2 milestone Feb 23, 2023
@ra3xdh ra3xdh mentioned this issue Feb 23, 2023
2 tasks
@tomhajjar
Copy link
Author

tomhajjar commented Mar 3, 2023

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
Copy link
Owner

ra3xdh commented Mar 4, 2023

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:

  • The Core model works only using Ngspice-27 and only using some specific diode models connected to secondary winding. For example it fails when I replace diodes by 1N400x device from library.
  • The full-wave rectifier simulation always fails to converge when using Ngspice-39

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
Copy link
Author

tomhajjar commented Mar 5, 2023

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
Copy link
Author

tomhajjar commented Mar 6, 2023

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
Copy link
Author

tomhajjar commented Mar 7, 2023

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
Copy link
Author

tomhajjar commented Mar 14, 2023

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
Copy link
Owner

ra3xdh commented Mar 16, 2023

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
Copy link
Author

tomhajjar commented Mar 16, 2023

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
Copy link
Author

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
Copy link
Author

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 ra3xdh modified the milestones: 1.0.2, 1.0.3 Apr 24, 2023
@ra3xdh ra3xdh modified the milestones: 1.0.3, 1.0.4 Jun 2, 2023
@ra3xdh
Copy link
Owner

ra3xdh commented Jun 22, 2023

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
Copy link
Owner

ra3xdh commented Jun 22, 2023

Here is the schematic file.

Core.zip

@ra3xdh ra3xdh self-assigned this Jun 22, 2023
@tomhajjar
Copy link
Author

tomhajjar commented Jun 23, 2023

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 ra3xdh added bug and removed question labels Jun 23, 2023
ra3xdh added a commit that referenced this issue Jun 23, 2023
@ra3xdh
Copy link
Owner

ra3xdh commented Jun 23, 2023

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
Copy link
Author

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
Copy link
Owner

ra3xdh commented Jun 23, 2023

Closing this as resolved.

@ra3xdh ra3xdh closed this as completed Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants