← Back to team overview

kicad-developers team mailing list archive

[PATCH] eeschema pspice netlist exporter alternative list.

 

Hello all,

Ngspice requires four nodes for a MOSFET component - nd ng ns nb, but most of ordirnary
KiCad MOSFET components have only 3 pins. I hoped to be able to provide the extra node using
the alternative list, something like: "1 2 3 3" i.e. mapping pin 3 to both ns and nb for example.
Unfortunately that doesn't work, because the netlist exporter only iterates over the KiCad
component pins, so any extra nodes provided in the alternative list are ignored.
I modified the netlist exporter for pspice to provide this extra flexibility.
Posting the patch here in case somebody else is looking for similar functionality.

--
Martin Stoilov
SigmaDrone - The Drone PC
www.sigmadrone.org

commit 9fe0daa6ea42daa28efb0f4109c5665e03b492e2
Author: Martin Stoilov <martin@xxxxxxxxxxxxxx>
Date:   Fri Feb 17 16:56:52 2017 -0800

    Fix the alternative node list to allow more nodes than the component pins.
    
    If the pspice required nodes are greater than the component pins
    we can supply alternative list that maps the same component pin
    to multiple pspice nodes. For example a 3-pin MOSFET component
    can be mapped to pspice MOSFET (which require 4 nodes) by
    providing alternative list: 1 2 3 3. This list will map pin 3 to
    both ns and nb.

diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp
index b2f65d2..2ebfab8 100644
--- a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp
+++ b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp
@@ -96,36 +96,16 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl
 
         aFormatter->Print( 0, "%c%s ", item.m_primitive, (const char*) item.m_refName.c_str() );
 
-        // Pins to node mapping
-        int activePinIndex = 0;
-
-        for( unsigned ii = 0; ii < item.m_pins.size(); ii++ )
+        size_t pspiceNodes = item.m_pinSequence.empty() ? item.m_pins.size() : item.m_pinSequence.size();
+        for( unsigned ii = 0; ii < pspiceNodes; ii++ )
         {
-            // Case of Alt Sequence definition with Unused/Invalid Node index:
+            int activePinIndex = item.m_pinSequence.empty() ? ii : item.m_pinSequence[ii];
             // Valid used Node Indexes are in the set
             // {0,1,2,...m_item.m_pin.size()-1}
-            if( !item.m_pinSequence.empty() )
-            {
-                // All Vector values must be less <= max package size
-                // And Total Vector size should be <= package size
-                if( ( (unsigned) item.m_pinSequence[ii] < item.m_pins.size() )
-                    && ( ii < item.m_pinSequence.size() ) )
-                {
-                    // Case of Alt Pin Sequence in control good Index:
-                    activePinIndex = item.m_pinSequence[ii];
-                }
-                else
-                {
-                    // Case of Alt Pin Sequence in control Bad Index or not using all
-                    // pins for simulation:
-                    wxASSERT_MSG( false, "Used an invalid pin number in node sequence" );
-                    continue;
-                }
-            }
-            // Case of Standard Pin Sequence in control:
-            else
+            if( (unsigned)activePinIndex >= item.m_pins.size() )
             {
-                activePinIndex = ii;
+                wxASSERT_MSG( false, "Used an invalid pin number in node sequence" );
+                continue;
             }
 
             NETLIST_OBJECT* pin = item.m_pins[activePinIndex];

Follow ups