I want to make the time-step and stopping-time in a trasient simulation scale automatically by using the parameter values (.PARAM lines) in the netlist. Here is a minimal ngspice etlist to demonstrate my use case.

How to access parameter values in transient simulation and interactive interpreter

.PARAM R = 1kOhm
.PARAM C = 1nF
.PARAM pi = 3.14159265359
.PARAM fb = {1/(2*pi*R*C)}  ; Q1. Why does pi need to be defined above?
.PARAM amplitude = 5V
.PARAM pointsPerCyle = 20
.PARAM numCycles = 1.5

VDD 1 0     SIN(0V {amplitude} {fb})
R1  1 2     {R}
C1  2 0     {C}

.TRAN {1/159kHz/20}         {1.5/159kHz}
* .TRAN {1/{fb}/{pointsPerCyle}}        {numCycles/fb}  ; Q2. How to access the parameter values defined above in tran sim?
.PLOT TRAN V(1) V(2)

    plot V(1) V(2)
    * plot {V(1)/{amplitude}} {V(2)/{amplitude}}    Q3. How to access the parameter values defined above in interactive interpreter and/or ngspice scripts?
    * print $fb
    * echo $R



The netlist will run as is, producing a transient simulation plot. The commented lines are where the errors occur. So I have 3 questions here.

  1. Why do I need to define pi in order to calculate some parameters? If it is already defined, I cannot access it at this point in the netlist (.PARAM lines)? Why?
  2. How do I access the .PARAM values to define the time-step and stop-tim in a trasient simulation?
  3. How do I access the .PARAM values in interactive interpreter and/or ngspice scripts?

Thank you!

  • \$\begingroup\$ It might be useful to show an example of where you can't access pi, it may be how your referencing it. \$\endgroup\$
    – Voltage Spike
    Aug 31, 2016 at 20:14
  • 2
    \$\begingroup\$ I often specify .param variable names in the .tran expressions, using the {} braces you already are using. I do it all the time, so I have no idea what you are asking. It just works. I will often use .param to set f=159k, for example. Then apply in in the formula as just f. Just works fine. \$\endgroup\$
    – jonk
    Aug 31, 2016 at 20:19
  • \$\begingroup\$ @laptop2d, The included netlist shows an instance where pi cannot be used in a calculation unless explicitly defined by the user as another parameter (line 5 and 6). \$\endgroup\$
    – Aamir
    Aug 31, 2016 at 20:31
  • \$\begingroup\$ @jonk I also expect it to just work. But it doesn't. Could you please execute the included netlist after commenting the line .TRAN {1/159kHz/20} {1.5/159kHz} and uncommenting the line * .TRAN {1/{fb}/{pointsPerCyle}} {numCycles/fb} ; Q2. How to access the parameter values defined above in tran sim? \$\endgroup\$
    – Aamir
    Aug 31, 2016 at 20:34
  • 2
    \$\begingroup\$ NGSpice seems to be fussy about syntax for expressions involving parameters. You might find `{numCycles/fb}` works where {numCycles/fb} doesn't (etc) \$\endgroup\$
    – user16324
    Aug 31, 2016 at 20:50

1 Answer 1


I also had the problem for some time, the answer is to use CSPARAM.

Description from NGspice manual:

description from NGspice manual


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.