I am working on a virtual reality engine in electrical engineering and am trying to implement the work of a function generator and an oscilloscope. The engine uses SPICE (NGSPICE) for circiut simulation.
I am having the following problem when implementing the behaviour of an oscilloscope.The simulation is based on a transient simulation (.tran tstep tstop). When the waveform is sinusoidal (SIN(0 Amplitude Frequency)) or triangular (PULSE ( V1 V2 TD TR TF PW PER )) there are no problems and the simulation completes fast.
When the voltage source create square waveform with PULSE ( V1 V2 TD TR TF PW PER ) and the tstop of the transient simulation is not very high (the TIME/DIV of t he oscilloscope is not too high), everything is okay. However when tstop is much much larger than the period of the square save (for example TIME/DIV=5s), the simulation takes a couple of seconds to complete, even though the number of required samples doesn't change (less than 1000).
I suppose the problem is that the PULSE voltage sources creates very high-frequency harmonic components (when used as square waveform source), which automatically reduces the timestep (tstep) of the transient simulation. So my question is is there a way to reduce the number of harmonics of the PULSE function, in order to reduce the simulation time?
Obviously another solution would be to use the nonsinusoidal waveform theory and connect multiple sinusoidal voltage sources in series with different frequencyes/amplitues/phase shifts in order to create the required waveform, however i wonder if there is an easier solution.