* this is a windows compare if input voltage
* over the cmp+ voltage output set 5V flag=1
* At flag=1, the voltage is below cmp- output set 0 and flag=0
* Name
* | Signal input
* | | output state
* | | | output refernce
* | | | | high limit
* | | | | | low limit
* | | | | | | output revers
.subckt WindowCMP IN OUT GND CMP+ CMP- OUTN
* Subcircuit Body
.model SW_XUTONG SW(Ron=.52 Roff=1Meg Vt=3 Vh=-.5 )
V1 5V GND 5
R1 OUT GND 1K
R2 OUTN 5V 1K
S1 OUTN GND OUT GND SW_XUTONG
.machCMP
*define two state
.state flag1 5
.state flag0 0
* old new
.rule flag1 flag0 V(IN)<V(CMP-)
.rule flag0 flag1 V(IN)>V(CMP+)
.output (OUT) state
.endmachCMP
.ends WindowCMP
用到了状态机写法