Electronic – LTspice: behavioral modelling elements for propagation delay

behavioral-sourcedigital-logicltspicesimulationspice

I'm trying to create a subcircuit in SPICE (currently using LTspice but want a pretty agnostic model) for an AND gate that delays an input by some amount TPD.

I'm currently just inputting 2 offest clock signals to the following subcircuit:

.SUBCKT AND_GATE_TEST A B OUT VCC VEE
    XOUTLOGIC A B OUT_LOGIC VCC VEE LOGIC_FUNCTION
    XOUTPD OUT_LOGIC OUT VCC VEE PD_FUNCTION
.ENDS

************************************************************

.SUBCKT LOGIC_FUNCTION  A B OUT VCC VEE

    GAND VEE N1 VALUE = {V(A,VEE)*V(B,VEE)} 
    RN1 N1 VEE 1    
    EOUT1 OUT VEE N1 VEE 1
    
.ENDS

************************************************************

.SUBCKT PD_FUNCTION IN OUT VCC VEE
    
    GDEL VEE N1 VALUE = {V(IN,VEE)}
    RN1 N1 VEE 1
    EDEL = OUT VEE DELAY N1 VEE TD=10ns
    
.ENDS 

The first logic function works fine and outputs the expected AND logic given the inputs A and B but I get tripped up with the propagation delay function.

The error that LTspice outputs says Missing gain value but no matter how I use the E element (or any behavioral elements for that matter) as a delay function I can't get it to work properly.

I think I'm missing something fundamental on the syntax of the behavioral elements

Any help on how to best approach this would be greatly appreciated.

Best Answer

What you have there is not exactly an AND, because if the inputs don't have logical levels of [0:1], you're in trouble. And that syntax is not SPICE friendly, so it must be some proprietary way of defining a delay.

For an agnostic model you could use a behavioural source and a transmission line with:

B1 0 1 I = V(a) & V(b)
T1 1 0 out 0 Td={td} Z0=1
R1 out 0 1

where I used & for the logical AND. IIRC, ngspice uses &&, others may have their notations, as well, but the behavioural source shoud be SPICE compatible. If not, at the expense of manually setting the output levels, you could use:

I = Vlow + (Vhigh - Vlow) * ( ( u(V(a) - (Vhigh + Vlow) / 2) ) * (u(v(b) - (Vhigh + Vlow) / 2 ) ) )

I think u() is SPICE compatible. I've also avoided the use of the builtin delay() (or absdelay()) because 1) it might be particular to LTspice (or only a few), and 2) the tline is SPICE compatible (and better behaved for fixed delays). The output resistance can be changed to have other values, in which case the expression in the current source would have to be changed to (<expression>)/R and the transmission line's impedance to Z0={R}.

Otherwise, if you can tolerate an LTspice-only solution, I would highly recommend the builtin A-device [Digital]/and with td={td} (you may also want to use tau and tripdt, or vhigh, vlow, etc, see more in the help).