Arbitrary voltage signal in transcient simulation

Is it currently possible to use an arbitrary set of samples from a file as input in a voltage source? How?

I guess it’s time for you to read the ngSpice manual. I see a bunch of references to reading from, and writing to files.

A simple search: https://html.duckduckgo.com/html?q=ngspice+wavefile+input also finds stuff like:

the ngSpice manual also mentions an interface to GNU Octave in chapter 18.8.7

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

I followed your suggestion but I always get

...
doAnalyses: TRAN:  Timestep too small; initial timepoint: cause unrecorded.
run simulation(s) aborted

This is my circuit:

and this is my simulation config:

I am using your .sub model and your .txt file.

Do you know what could be the issue?

There is also already another topic about this: NGspice simulation of Wave File

No, because there is not enough information. Please post the complete project (including all models used) as a *.zip file here. I then could have a look.

arbitrary_waveforms_test.zip (6.8 KB)

You have defined a voltage source driven from tabulated values with 2 outputs n1 and n2. In your circuit you are short-circuiting the lower (n2) node of the source to GND. This is not allowed, as a node cannot be GND and voltage output at the same time. You may add another resistor between V1 and GND to decouple n2 from GND.

This topic was automatically closed after 90 days. New replies are no longer allowed.