gnetlist: spice-sdb: Add "write-prefix" to all "write-" functions.

Bug #1161063 reported by tvrusso
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
gEDA
Confirmed
High
Unassigned

Bug Description

The functions like write-npn-bipolar-transistor all include a call to "write-prefix" to assure that the netlisted device always has a Q as the first character on the SPICE netlist line. (or an M for mosfet, or an X for subcircuit, or...)

But the simple SPICE devices like resistor, capacitor, and inductor do not.

This is inconsequential when spice-sdb is used as intended, to generate hierarchical netlists using the HOWTO that Stuart Brorson wrote. But while this HOWTO shows how to create a really nice subcircuited netlist for spice, it does not allow one to use the nice hierarchical *schematic* features of gschem (where one associates a source schematic in a symbol with "source=foo.sch" instead of a source subcircuit file with "file=foo.cir").

I tried creating a hierarchical schematic and netlisting with spice-sdb and it mostly worked, but passives like resistors and capacitors were written with device names like "S1/R1" or "S1/C1".

It was really simple to fix this by adding

         (spice-sdb:write-prefix package "R" port) ;; this prepends an R if needed.

immediately before the lines:
     ;; first write out refdes and attached nets
     (spice-sdb:write-component-no-value package port)

This prepends an R to the refdes if the refdes doesn't already have one, which will be the case for a hierarchical netlist. Once this is done, sub-schematics containing resistors, capacitors and inductors will properly be netlisted when not using the spice-subcircuit-LL and spice-subcircuit-IO technique.

I will attach a patch that fixes these three devices, and a tar file of a project that demonstrates the use of hierarchical schematics. It is improperly netlisted by gnet-spice-sdb.scm before this patch, and netlisted in a manner that works in SPICE after applying the patch.

The patch does NOT fix other simple SPICE devices such as voltage sources (including dependent sources), switches, etc. Those will also need fixing and probably require only the addition of a single line per write-function, as with the three I've patched here.

Revision history for this message
tvrusso (russo-bogodyn) wrote :
Revision history for this message
tvrusso (russo-bogodyn) wrote :

This file is a tar file containing a simple hierarchical schematic (a common emitter amplifier and a driver circuit for it). When netlisted with :
    gnetlist -g spice-sdb CE_Amplifier.sch

the resulting netlist incorrectly has the lower-level resistors and capacitors named "S1/R1", "S1/C1", etc. SPICE will not simulate that netlist correctly, as it will treat all of those devices as switches instead.

With the attached patch, these devices are output as "RS1/R1", "CS1/C1" etc. The resulting netlist simulates properly in SPICE.

Again, my patch only fixes the three simple passives, not all of the devices that are missing "write-prefix" calls.

Peter TB Brett (peter-b)
tags: added: gnetlist
Revision history for this message
Gag (renaud-gaglione) wrote :

Dear all,
I am quite new to geda/ngspice, but I am trying to perform some "simple hierarchical simulation" (like I do at work with Cadence and Spectre).
As you said, with original netlist and "Sx" subcircuit (or, better, component), ngspice is unable to evaluate the passive.
This prefix seems to be the beging of the solution for me. But ngspice still do not want to simulate my netlist : it seels that the "/" create a problem.
With the option (hierarchy-uref-separator "") in gnetlistrc (and the prefix patch), we obtain an ngspice simulable netlist.

So, I'm very interested to see this patch in the next release !
Regards,RG

Revision history for this message
Gag (renaud-gaglione) wrote :
Peter TB Brett (peter-b)
Changed in geda:
status: New → Confirmed
importance: Undecided → High
milestone: none → 1.9.2
Revision history for this message
Gag (renaud-gaglione) wrote :

Dear all,

I encounter some problems even with the patch (assuming that subsheets refdes is X, otherwise a lot of limitation appear, first of all the depth of the hierarchy).
A problem encountered is inclusion of voltage source inside the hierarchy (NOT at top level). Thus, the voltage source is not recognized by gnetlist.

A workaround is to set the option (hierarchy-uref-order "prepend") : thus the component names start by the component type (A to Z), and thus the patch is not necessary any more.
Beside, I found convenient to set (hierarchy-netname-separator "_") and (hierarchy-uref-separator "_"), as "/" is unfortunately not understood correctly by ngspice (by the way, well interpreted by Cadence Spectre !).

I hope this will help towards real and simple hierarchical simulation, because I like simulate the same schematic that is exported too pcb.
Sorry for may bad english, I hope that it is understandable.

RG

tags: added: spice-sdb
Changed in geda:
milestone: 1.9.2 → 1.9.3
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.