Reference manual for C block

Hello Mike and Qspice team,

Congrats on the Qspice release!
I’m checking out its features … Is there a reference manual for C functions?

For example, topics that I’m interested:

  1. A tutorial video showed the port of a C block can be a voltage source. But can it be a current source, or a voltage source with internal impedance?

  2. Can we model PWL inductance/capacitance with C block?

  3. Can we use C algorithm to detect steady state, then terminate the simulation session early?

  4. Can the C block write data to a file?

  5. Does the C block support event statement, such as using timer, voltage crossing a threshold, and so on, to invoke a function (e.g. toggle a PWM pin)?

Also, is it possible to script the post processor, in other words, automatically compute the measurement time window = t_end - 100us, where t_end may be a parameter or a dynamic decision from #5? Alternately, is there a manual about output data format, so that external scripts can do the post processing from waveform data?

So many questions. Thank you in advance!

Jerry

1 Like

You’ll want to study the PracticalSMPS.qsch example.

The point to writing in C++ or Verilog in QSPICE is that it allows you to present an essentially unlimited amount of logic to a SPICE simulation. It isn’t for modeling analog components even though I prefer to pass real numbers to the C++ unlike many old-fashioned native Verilog speakers.

But to answer your questions:

…But can it be a current source, or a voltage source with internal impedance?

You specify ROUT. Defaults to 1kOhm. It is not a voltage source.

Can we model PWL inductance/capacitance with C block?

No, but there are already arbitrary reactances on the SPICE side.

Can we use C algorithm to detect steady state, then terminate the simulation session early?

You can write a routine to detect what ever you chose to call steady state and then output whatever signals you want. If you want, you can terminate the simulation with a call to exit(0), not that I imagine that as useful.

Can the C block write data to a file?

Yes. Just include the appropriate headers. Anything a C+ program can do, you can do in the .DLL.

Does the C block support event statement…

You’d have to implement that. The point to the C++ interface in QSPICE is that it allows you code very close to the metal. You can even spill over to assembly language with an __asm{} block. You aren’t restricted to some framework or that framework’s concept of an event.

Again, study the PracticalSMPS.qsch example.

–Mike

Hi Mike,

Thank you very much for your reply.
Now I have a better idea of the C block concept. I will study the example as well.

Regards,
Jerry