Question about recalculation of previous iterations

Just out of curiosity. I heard somewhere that Qspice can go back in time and recalculate some previous iterations if necessary. Is this true? Is this a new feature compared with LTspice?
Can someone provide more info?

I dont use LTspice that much.

However, I believe backward timestep are implemented both in Qspice and LTspice (all flavor of spices) whenever a discontinuity is detected.

One possible reason why it matters more for us now is due to the introduction of C block/Verilog where we can actively manipulate the timestep.

Let see if Mike will response to this question. I have this same question just never ask about that.

When I study TTOL, it is expected that timestep is reduced after TTOL condition is met, but what interesting is that, I can observe from waveform, before TTOL condition, timestep also reduced. This phenomenon suggests Qspice may go back in time for recalculation.


Without TTOL

1 Like

Thanks. I was also thinking about C++ modules.
How do you actively manipulate the timestep in C++?

In my device guideline, section Ø-Device .DLL (in about page 211), with example to explain ttol in C++ modules. It is related to Trunc() template.
Qspice/Guideline/Qspice - Device Reference Guide by KSKelvin.pdf at main · KSKelvin-Github/Qspice

@RDunn has various documentation and tools relevant to C-Block component in his Github
QSpice/CBlock_Doc at main · robdunn4/QSpice (


You can first make a simple DCM buck simulation. Then try to use a simple C block, then do this:

print(t - t_prev);
t_prev = t;

Remember to not use the struct to store the t_prev value.

Then, you can see that the printed value will not always be positive, especially right around the discontinuity event.


About the effective manipulation of timestep, you can see my various implementation for complementary PWM.

  1. Using simple external comparator (with behavioral source and schmitt comparator) w/ and w/o deadtime
  2. Using C block only, w/ and w/o deadtime

The C block implementation accurately mimic the behavior of MCU pwm generation, while being very time efficient.


@marcos.uniovi ,

I am aware you can change the maximum size of the NEXT timestep using MaxExtStepSize(). Changing the return value of this function to a smaller value improves the resolution of the simulation.

I’m not aware that you can go backwards in time. However, having said that: If you feed a return value into MaxExtStepSize() of a negative time value, will time (variable ‘t’) go backward?

If true, this could pose a problem if MaxExtStepSize() is left with this negative timestep value. The simulation will never proceed forward.


1 Like

You may just manipulate *timestep from within Trunc() instead of maxtimestep.

I dont know if you may ever need to activately set negative timestep, for me negative timestep is only for Spice solver to ensure discontinuity event within the circuit are occured at the correct time.

1 Like