Using NGSpice - missing primitive libraries symbols

u is the standard spice notion for micro.

What type of µ character should be translated to u? Keyboard µ and utf-8 µ seem to differ. Maybe we should check both.

Correct. (LTspice does its own thing by automatically replacing u with µ by default.)

I would guess to just check for CP1252 (= Windows Western but for µ it is the same for most Windows ANSI and ISO-8859 encodings) and UTF-8 codes (and maybe both UTF-16 codes)? I actually would like to see support for Ω and R (as decimal point for resistor values like 0R33 or R33) as well, but I don’t know how backward compatible that would be.

I have pushed a fix to ngspice git branch pre-master dealing with the micro µ (mu), translating it to u.

Franzee, if you are compiling ngspice, could you please check and test it?

Concerning Ω, best probably is to just ignore it, right?

That’s what some other SPICEs do, I guess, but something like 2Ω7 could then lead to unexpected 2.0Ω or 27Ω?

Thanks. Sorry, currently not compiling myself, but looks good, oops, I think it needs an additional copy after the loop (the trailing \0 needs to be included, and setting s[1] twice might get flagged by a code analyzer).

Just thinking, if UTF-8 is generally accepted as input, then doing it in 2 steps (first only fixing the ANSI/ISO encoding error by replacing µ with its UTF-8 sequence, and then handle µ like u at the evaluation stage) could lead to better diagnostics if there is an error printed later?

done

If have added a patch to improve reading R and C with RKM code.
Example files are provided in ngspice/examples/various.

1 Like

franzee,

question to a user:

For resistors RKM (https://en.wikipedia.org/wiki/RKM_code) prescribes letter L for milli, letter M for meg.

People are used to 25m being 25 milliOhms.

Unfortunately ngspice cannot distinguish between upper and lower case letters, so M versus m does not help. What are others (LTSPICE) doing? What would be the best choice: stick to RKM, when ngbehavoir is set to LT, or doing something else?

LTspice’s setting for RKM code is poorly documented because its control panel description only explicitly calls out K (kilo).

image

But if checked (which is the default), it works with any of the standard engineering multipliers. So you can write 2meg2 to make a 2.2 megaohm resistor. In the LTspice GUI, if you try to use only a capital M, it will force it to lowercase. But even if you bypass the GUI and run a straight netlist with capital M it will still imply lowercase m in the SPICE engine.

As for the µ thing, if you look using a hex editor at the .net file that is automatically generated during simulation runs, LTspice uses 0xB5 in ASCII. So…I think just convert 0xB5 -> 0x75 ?

As @Ste writes, it’s a bit tricky in LTspice. For SPICE value evaluation, all is case independent for backward compatibility. However, the GUI for the graphs treats m and M (and only these 2) in expressions as distinct (this is not relevant to ngspice, I think). The GUI for the schematics also automatically replaces e.g. meg with Meg, M with m and u with µ after entering a value, so 3M3 shows up already as 3m3.

If Accept 3K4 is not checked, then /MEG|MIL|µ|μ|%|[FPNUMKGT]/i (but only both lowercase μ, not uppercase Greek Μ) is recognized as suffix of a floating point value (including +, -, . and e), and the (alphanumerical) rest is being ignored (meg is 1e6, mil is 25.4e-6, any other m is 1e-3, % is 1e-2). E.g. 1E2MΩ would be 0.1, 3.3m3 would be 0.00330, 3m3 would be 0.00300, 3R3 would be 3.

If Accept 3K4 is checked (default), then additionally to above, and only if it’s an integer value instead of a floating point value, trailing digits (without .) are also recognized (plus R and r can act as .). E.g. 3.3m3 and 3m3 would be 0.00330, 3R3 would be 3.3, 3%3 would be 0.033 (not modulo), 3Ω3 would (unfortunately) still be 3.0.

The KiCad GUI, on the other hand, replaces uppercase M with Meg in the netlist for both, ngspice and LTspice, if ☑ Adjust passive symbol values (e.g. M -> Meg; 100 nF -> 100n).

1 Like

O.k.

So after my next update ngspice will follow the RKM rules with 2 exceptions:

  • Upper case and lower case letters are not distinguished.

  • Letters m, M denote milli (1e-3), letters Meg or meg denote 1e6. KiCad will give it another flavor in that upper case M is meg, again according to RKM.

2 Likes

Not sure if I’m reading it correctly, but LTspice uses f and F for femto (it ignores f or F if it’s in the rest mentioned above), so 4F7 is actually 4.7e-15 (which trips people sometimes). LTspice doesn’t support any L, so maybe lowercase L should be an error or warning (it’s likely a typo)?

1 Like

That’s what I have just changed (back) again.

I cannot detect lower or upper case letters, because during reading (with some exceptions) everything is converted to lower case.

2 Likes