Arbitrary voltage signal in transcient simulation

ngspice manual (Download ngspice-43-manual.pdf (ngspice) or Ngspice User's ManualVersion 43(ngspice release version)), chapter “8.2.9 Filesource (PWL sourced from file)”. In the manual for ngspice-42 or older this is chapter 12.2.9.

The filesource allows reading a table from a file. Its first column is the time, the next column(s) are one or more data points at the specific time in the first place of the row.

A simple plain ngspice (not KiCad) example is available at ngspice / ngspice / [2af390] /examples/xspice/filesource

How to make use of such a filesource in KiCad?

Let’s assume the example given above (table with time and two outputs in file my-source.txt).

You will need an Eeschema symbol with 2 outputs. This symbol requires a spice model for simulation. So we have to create one, a subcircuit model.

.subckt twosource n1 n2

* filesource instance
A1 %vd([n1 0 n2 0]) filesrc

* filesource non-interpolating model 
.model filesrc filesource (file="my-source.txt"
+ amploffset=[0.1 0.1] amplscale=[3.0 3.0]
+ timeoffset=0 timescale=1
+ timerelative=false amplstep=true)

.ends

This model may now be put into a file (e.g. filesource.mod) and then attached to the symbol in the usual way. Of course you may edit the filesource model parameters according to your needs.

The model parameter

file="my-source.txt"

may require an absolute file path.

1 Like