Spectrum Software has released Micro-Cap 11, the eleventh generation of our
SPICE circuit simulator.
For users of previous Micro-Cap versions, check out the
new features available in the latest version. For those of you who are
new to Micro-Cap, take our
features tour to see what Micro-Cap has to offer.
Storing the Time of an Event
In some cases, a circuit may need a time based element that is triggered when an event elsewhere in the circuit occurs. Micro-Cap has the t variable, which is the value of the simulation time in transient analysis, in order to include time in circuit expressions. However, practical use of this variable assumes the expression starts at t=0 or that the time of the triggering event is known. If the time of the triggering event is unknown, then that event time must be dynamically stored in the circuit for use in an expression. The circuit below displays a technique for storing the time that an event occurs.
In this circuit, the time that the switch opens is used as a reference in a time based exponential waveform. The trigger portion of the circuit consists of a battery, a switch, and a resistor. The nodes swp and swn will essentially be shorted when the switch is closed and will have approximately 10V across them when the switch is open. The sources within the dashed box monitor the switch voltage and will store the time that the switch opens. The S1 source is a sample and hold source. Its EXPR attribute is defined as:
which is the voltage across E1, and it is sampling the voltage every 1ns. The NFV source, E1, has its VALUE attribute defined as:
The output of the E1 source will be the time of the simulation when V(swp,swn) is less than 2 and will be the value of the S1 source when V(swp,swn) is greater than or equal to 2. The S1 source mirrors the E1 source which is a ramp of voltage equal to the simulation time until the switch opens, when both voltage sources lock on to the value of the last time stored in the sample and hold when the switch was closed. If the sample period of the sample and hold source is small relative to the simulation time, this stored value will essentially be the time that the event occurs. This value will be stored in both sources until the switch closes upon which the sources will again have the value of the current simulation time. Note that the sampling period of the sample and hold source will limit the maximum timestep of the simulation and may effect the speed of the simulation if set very small. The voltage of either the E1 or S1 sources may subsequently be used in other equations as a time reference. The NFV source, E2, has its VALUE attribute defined as:
When the switch is closed, the source will produce a constant 10V since t and v(tevent) are equivalent. When the switch opens, the source produces an exponentially decaying source using the v(tevent) voltage as a reference.
The results of the simulation are displayed in the plots below. The top waveform is the voltage across the switch, v(swp,swn), with the switch opening at 500ns. The middle waveform is the voltage of the E1 source, v(tevent). As can be seen in the plot, when the switch opens, the voltage at this node locks in at the time of the event which in this case is 500nV. The bottom waveform is the voltage of the E2 source, v(out), and begins its exponential decay upon the opening of the switch.
This storage technique will work with any other dynamic circuit expression such as voltage, current, instantaneous power, etc. In the If statement, simply replace the variable t with the desired expression that is to be stored.