USING EASYHDL TO SPECIFY ANALOGUE SIGNALS

Declaring the Output(s)

The output pin(s) for an analogue scriptable generator should be declared as NODE variables. For example:

NODE V(OUT)       // Single voltage output

NODE V(POS,NEG)   // Differential voltage output

NODE I(OUT)       // Single ended current output

NODE I(POS,NEG)   // Current output

A local generator script contains an implicit declaration of NODE V(OUT) for a voltage generator or NODE I(OUT) for a current generator. A script that is placed on the schematic or held in a VSM Studio project has no implicit output, so each generator it drives must be declared explicitly.

Program Flow

When an EasyHDL script is used to specify analogue signals, the entire script is executed from top to bottom at each analogue timepoint and also whenever a callback event occurs. Two commands are rejected in an analogue script, SLEEP and WAIT, both of which suspend the script part way through; either produces a run-time error. The assumption is that the program will make assignments to all the declared NODE variables.

Callback events may be scheduled using either the CALLBACK or TIMER commands. These commands cause an analogue simulation timepoint to occur at the specified time and the script to be invoked with a corresponding event id.

Typically, you will use mathematical formulae to specify the output at a particular time and then use callback events to change some of the parameters in the formula at specific times. If this sounds a little confusing the example below should help clarify the concept:

REM TRIANGLE WAVE GENERATOR

REM Define the Waveform Parameters

FLOAT FREQ=100, AMP=2, SLOPE=1

FLOAT PERIOD=1/FREQ,OFFSET=0

REM Repeating event for positive slope

ON TIMER AT PERIOD EVERY PERIOD

OFFSET=EVTTIME

SLOPE=1

ENDON

REM Repeating event for negative slope

ON TIMER AT PERIOD/2 EVERY PERIOD

OFFSET=EVTTIME

SLOPE=-1

ENDON

REM Set the output as a function of both time

REM and the current waveform slope.

OUT=AMP*SLOPE*(4*(REALTIME-OFFSET)/PERIOD-1)

The example is written as a local script, so OUT comes from the implicit NODE V(OUT) declaration described above. If you were to place the same code in a named script you would add that declaration yourself, using the name of the generator you want to drive.

When the script is invoked at an arbitrary timepoint, only the last line is executed. This specifies the output in terms of a voltage that will rise or fall linearly with time according to the value of SLOPE. This value is set alternately to 1 and -1 by the two ON TIMER blocks that trigger alternately every full and half cycle such that a triangle wave is produced.

It should also be apparent from this that variables hold their values between invocations. However, you must be careful not to make assumptions about how many times your script will be invoked over a given period of simulation time. For example:

REM !!!BAD CODE!!!

FLOAT VOUT=0

VOUT = VOUT + 1.0

OUT=VOUT

This will produce unpredictable results because the rate of rise of VOUT will depend entirely on the timesteps chosen by the SPICE kernel.

Controlling the Timestep

The BOUNDSTEP command places an upper bound on the timestep the SPICE kernel is allowed to take, so a script can guarantee itself a minimum invocation rate. It takes a single expression, in seconds, in parentheses:

BOUNDSTEP (10u)

Once the bound is in force the kernel will not advance by more than the given interval in a single step, although it remains free to take smaller steps where the circuit demands them. The bound applies from the point at which the command is executed and can be changed at any time, so a script can tighten it over a region of interest and relax it again afterwards. Passing a value of zero removes the bound.

A tight bound forces the simulator to compute more timepoints and will slow the simulation down, so set it no smaller than the waveform you are generating actually needs.

Specifying Output Transitions

You can specify the output of an analogue generator in one of two ways:

  • As an instantaneous value.
    OUT=vout
  • As a timed transition.
    OUT=vout AFTER time_interval

In the case of a timed transition, the output will ramp linearly from its current value to the destination value over the specified time interval. You can also specify an absolute destination time for the transition with

OUT=vout AT time

The example, below, shows how output transitions can be used to generate a piecewise linear waveform from stored data.

REM PIECEWISE LINEAR GENERATOR

REM Define time/value pairs for the output

DATA 2m,5

DATA 3m,5

DATA 5m,0

DATA 0,0 // End of data

FLOAT PERIOD=10m

FLOAT v,t,td

TIME OFFSET=0

REM Reset the data pointer to

REM start a new cycle

ON TIMER AT PERIOD EVERY PERIOD

   RESTORE

   OFFSET=EVTTIME

ENDON

ON EVENT

READ t,v

IF t > 0

  t = t + OFFSET

  OUT=v AT t // The output is set to voltage v at time t

  CALLBACK AT t

ENDIF

ENDON

See Also:

NODE Type

The BOUNDSTEP Command

The ON TIMER ... ENDON Command

The CALLBACK Command

REALTIME and EVTTIME System Variables