File: [Cherry]<Thyme>Cedar5.1>System>spFunctions.mesa
Last editted: Chen June 7, 1984 8:14:17 pm PDT

DIRECTORY
Real USING [FixI, RealException],
spGlobals USING [EnterFunctions, Failure, function];

spFunctions: CEDAR PROGRAM
IMPORTS Real, spGlobals
EXPORTS spGlobals=

BEGIN

functionError: SIGNAL[s: STRING]= CODE;

SimpleFET: spGlobals.function= {
-- args indices
Vgate: NAT= 0;
Vsource: NAT= 1;
Vdrain: NAT= 2;
-- parms indices
Vt: NAT= 0;
Gain: NAT= 1;

Vds, Vgst: REAL;

Vds← args[Vdrain] - args[Vsource];
IF Vds >= 0 THEN {
Vgst← args[Vgate] - args[Vsource] - parms[Vt];
v← IF Vgst > 0 THEN
IF Vds > Vgst THEN 0.5*parms[Gain]*Vgst*Vgst
ELSE parms[Gain]*(Vgst - 0.5*Vds)*Vds
ELSE v← 0.01*parms[Gain];
}
ELSE {
Vds← -Vds;
Vgst← args[Vgate] - args[Vdrain] - parms[Vt];
v← IF Vgst > 0 THEN
IF Vds > Vgst THEN -0.5*parms[Gain]*Vgst*Vgst
ELSE -parms[Gain]*(Vgst - 0.5*Vds)*Vds
ELSE v← -0.01*parms[Gain];
};
};
-- SimpleFET

PulseGen: spGlobals.function= {
-- parms indices
onLevel: NAT= 0;
offLevel: NAT= 1;
period: NAT= 2;
width: NAT= 3;
tRise: NAT= 4;
tFall: NAT= 5;
tDelay: NAT= 6;

time: REAL← t - parms[tDelay];
nperiods: INTEGER← Real.FixI[time/parms[period]
! Real.RealException=> spGlobals.Failure[750]];
tRel: REAL← IF time > 0.0 THEN time - nperiods*parms[period]
ELSE time + (1 - nperiods)*parms[period];
v← IF tRel >= parms[width] THEN parms[offLevel]
ELSE
IF tRel < parms[tRise] THEN
parms[offLevel] + (parms[onLevel] -
parms[offLevel])*tRel/parms[tRise]
ELSE
IF tRel <= parms[width] - parms[tFall] THEN parms[onLevel]
ELSE parms[offLevel] + (parms[width] - tRel)*
(parms[onLevel] - parms[offLevel])/parms[tFall];
};
-- PulseGen

OneShotGen: spGlobals.function= {
onLevel: NAT= 0;
offLevel: NAT= 1;
width: NAT= 2;
tRise: NAT= 3;
tFall: NAT= 4;
tDelay: NAT= 5;

tRel: REAL← t - parms[tDelay];

v← IF tRel < 0.0 OR tRel >= parms[width] THEN parms[offLevel]
ELSE
IF tRel < parms[tRise] THEN
parms[offLevel] + (parms[onLevel] -
parms[offLevel])*tRel/parms[tRise]
ELSE
IF tRel <= parms[width] - parms[tFall] THEN parms[onLevel]
ELSE parms[offLevel] + (parms[width] - tRel)*
(parms[onLevel] - parms[offLevel])/parms[tFall];
};
-- OneShotGen

StepGen: spGlobals.function= {
onLevel: NAT= 0;
offLevel: NAT= 1;
tRise: NAT= 2;
tDelay: NAT= 3;

v← IF t <= parms[tDelay] THEN parms[offLevel]
ELSE
IF t >= parms[tDelay] + parms[tRise] THEN parms[onLevel]
ELSE parms[offLevel] + (t - parms[tDelay])*
(parms[onLevel] - parms[offLevel])/parms[tRise];
};
-- StepGen

spGlobals.EnterFunctions["OneShotGen", OneShotGen, 0, 6];
spGlobals.EnterFunctions["PulseGen", PulseGen, 0, 7];
spGlobals.EnterFunctions["SimpleFET", SimpleFET, 3, 2];
spGlobals.EnterFunctions["StepGen", StepGen, 0, 4];

END.
CHANGE LOG
Wilhem, April 6, 1982 12:17 PM
Barth, 7-May-82 10:56:56 PDT
Chen, June 7, 1984 8:14:24 pm PDT, cedarized.