Simple use of an in-file .SUBCIR definition in a simple circuit not working


I realize I’m probably doing something that should be simple … wrong.

Here’s my .qsch file. I’m using the QN component and symbol. I renamed the 1st attribute to PMBT3904. The name of the actual device.

I included the .SUBCIR definition given by the manufacturer directly into the .qsch.

When I run the sim, I get:
Didn’t find a model for “PMBT3904” – defaults assumed.

I’m assuming since the name of the subcircuit matches the name of the NPN, it would use this. Apparently not.

Any ideas?

NPN_test.qsch (4.6 KB)

It not working because you place a Q (transistor) and force its to accept a .subckt directly.
If you place a Q, its Symbol Type is Q, and it only accept transistor model syntax, i.e. .model statement.
But, you can turn a Q symbol into subckt symbol, by right click Q1, in Symbol Type, select “X” (capital X), and delete NPN.txt in Library File. This action can turn a Q symbol to become a subckt symbol. Just be careful that .subckt assign pin according to its order, so, in this case, .subckt pin order is 1 2 3, Q symbol pin order is C B E, and they match each other in C B E definition, therefore, you can take Q symbol for this .subckt. But if you .subckt is not in C B E order, don’t use this trick.

As you included .subckt in schematic, you don’t need to specify a library path and simulation should work in this way. But subckt doesn’t support current measurement yet, if you want to measure Ic and Ib, you have to add a 0V voltage source for that.

Or, for .subckt, a more simple method is just copy and paste .subckt into schematic, autogenerate a symbol for that. But if you want a transistor symbol for this one, above trick should work for you. Here I attach modified .qsch for your reference.

NPN_Q2SubCKT.qsch (6.2 KB)

1 Like

Or, for this .subckt, you can directly implement its with Q and D from its .model and remove its subckt. With this you can reserve advantage of using Q and D symbol which offer direct current readback.

NPN_UseQandD.qsch (5.4 KB)

1 Like

@KSKelvin ,

Thank you, thank you, thank you!

I knew is was something simple that I missed.


1 Like

I have to jump on this tread since it is of interest for me. What I need most of the time is to place many transistor models in a single file, including package parasitics. Then select the specific subcircuit I need for my application, using a single file with hundreds of different subcircuits inside. It is vital to work with subcircuits only, never with models. It would be a disaster to be forced to use X as a PART NUMBER as opposed of using Q or whatever other significant descriptive name I need. Fortunately, QSPICE allows to define the type as X and the NAME as whatever you need.
There are some issues with QSPICE using subcircuit models from a single file, not quite sure yet when. I am still trying to figure out if there are some bugs or I missed something. For the most part, QSPICE works just fine with subcircuits. If the example I provided below does not work, it is because I cannot upload a ZIP archive, and maybe some files are missing.
000_test.qsch (35.4 KB)
BIP-NPN.qsym (10.1 KB)
BIP-NPN.txt (13.6 KB)
BIP-PNP.qsym (850 Bytes)
BIP-PNP.txt (10.7 KB)

1 Like

An important concept in Qspice for sybmol is that, in Symbol Properties > Library File, it can have these three options

  1. Nothing : You need to use .lib directive to assign library path
  2. A library with or without path : Symbol will search its model from this library file
  3. |.SUBCKT… : Normally this is created when you copy and paste .subckt with autogenerated symbol. Qspice allow entire .subckt bundle into a symbol with this method, and you only have to share your symbol/schematic without library document

A quick look of your two symbol (BIN-NPN.qsym and BIP-PNP.qsym)

  • BIN-NPN.qsym : This is Option 3, this means BIN-NPN.txt is not needed anymore
  • BIP-PNP.qsym : This is Option 2, Qspice looks for library BIP-PNP.txt from the path D:\work\projects\000_KiCad_lib\QSPICE\ when you run your simulation.

1 Like