2

I am running LTspice in batch mode on my Windows. However, I am now migrating to Linux, where the alternative to LTspice is Ngspice. The problem I am facing is the following:

In my LTspice netlist I have different behavioral voltages that are defined with lookup tables as follows:

V1 1 0 AC 1
XR1 1 0 Rskin
.subckt Rskin 1 2
R1 1 11 1n ; <= to avoid parallel voltage sources
V1 11 10 0
B2 10 2 V=I(V1) MAG FREQ=
.inc Rskin.inc
.ends
.ac dec 6 1 100k

Example taken from here. Where Rskin.inc file contains a table of (freq,mag,phase) of the frequency behavior of the resistance.

So, a part from the control section that ought be added in the NGspice netlist

.control
set filetype=binary
set ngbehavior = lta
run
write path_2my_netlist all
.endc
.end 

where I specify that the ngspice behavior should be that of LTspice, what else is there to do to have this netlist sample run on Ngspice. I still get the error :

Undefined number [mag]

PS: Wine is not an option.

Wallflower
  • 449
  • 3
  • 10
  • It looks like `MAG FREQ=` is not recognized, so it might be that it defaults to `dB FREQ=` (e.g. `freq, dB, phase[deg]` triplets) -- which means it's not needed to add the `dB` keyword. If your data is made for `MAG FREQ=` then you'll need to convert it to dB (if, indeed, Ngspice does not recognize that). – a concerned citizen Aug 16 '22 at 09:44
  • @aconcernedcitizen Even when I delete the ```MAG``` and leave it just to ```FREQ```, I still get an error: ```freq undefined```... – Wallflower Aug 16 '22 at 09:47
  • I'm looking through the manual (v32) and I can't see anywhere `FREQ`, so it could be that Ngspice doesn't support the syntax. If so, it's a surprise, since that has been a part of SPICE for some time now. Most probably I don't know where to look for. Try using a CCVS like this, instead: `H2 10 2 V1 FREQ=...`. Or use the CCVS for current conversion with voltage output at node `xxx`, then use a VCVS: `E2 10 2 xxx 0 FREQ=...`. – a concerned citizen Aug 16 '22 at 09:53
  • @aconcernedcitizen NGspice shuts down immediately with no error whatsoever.... – Wallflower Aug 16 '22 at 11:14
  • 1
    Well, that's encouraging. I guess the syntax is not known. If true, your only other option is to approximate the response with RLC elements. But, if you're using [this file](https://groups.io/g/LTspice/files/z_groups.io/Examples/Educational/Skin_Effect_Resistor.zip) then the comment above lists a frequency-domain expression, so you can use `Laplace` (which Ngspice does know). – a concerned citizen Aug 16 '22 at 12:57
  • @aconcernedcitizen Well, approximating with the RLC elements is to be forsaken for my work, lol. I guess I will try to use the ```Laplace``` function which I completely forgot about. However, it needs fitting too right? I can't just include the 'lookup' table? – Wallflower Aug 16 '22 at 13:00
  • The Windows version of LTspice runs on Linux under Wine. It's specifically designed to do that by the author. A lot of people with Macs actually hate the native Mac version and run the Windows one through something like "WineBottler" or equivalent. – Ste Kulov Aug 16 '22 at 18:01
  • 1
    @SteKulov Thank you for your comment, but I have specified in the question that Wine is not an option. The lab is against it for 'security reasons'... – Wallflower Aug 16 '22 at 20:54
  • 1
    Whoops. Roger that. I would've started out your question with that (including the reason) instead of tacking it at the bottom. You're statement of "...migrating to Linux, where the alternative to LTspice is Ngspice." is what threw me off. It's "an" alternative but not "the" alternative until you explain your constraints. Anyway, the answer is below is good. Check my link under the comments there for statements made by one of the ngspice authors regarding the `FREQ` command. – Ste Kulov Aug 17 '22 at 02:41
  • @SteKulov Understood for future posts ;). Will do, thank you for your help! – Wallflower Aug 17 '22 at 07:57

1 Answers1

2

I'll make this an answer, since Ngspice does, indeed, not know the FREQ syntax. But, if your example is this circuit then you have there a Laplace expression, just copy-paste it, since freq is an alias for s. Otherwise it looks like your only other alternative is an RLC approach. It's not that bad, if things are this (relatively) simple. For example, these series RL sections, all in parallel, give a purty good approximation, though a tad higher magnitude:

L1 a b 10u rser=20m
L2 a b 5u rser=30m
L3 a b 3u rser=40m
L4 a b 2u rser=50m

OTOH, you now get a phase which, with the FREQ approach, did not have. Also, that Laplace expression is not exactly quite like the FREQ approach, either...

a concerned citizen
  • 21,167
  • 1
  • 20
  • 40
  • 2
    Just adding a reference highlighting that FREQ is currently not supported in ngspice, but anyone willing to do it can volunteer writing the code for it! https://forum.kicad.info/t/import-target-function-for-ngspice/26907/5 – Ste Kulov Aug 16 '22 at 18:06
  • 2
    @SteKulov Thanks for the link. I saw it being discussed in the group, but not the link. – a concerned citizen Aug 16 '22 at 18:29