Electronic – Current controlled switch with negative current

ngspicespice

I am trying to create a current controlled switch, which opens only at negative current, I tried this approach:

Wswitch com no Vcurrent negative_switch                        
.model negative_switch CSW it < 1nA ih=0 ron=1n roff=1g

but, I got error:

unrecognized parameter (<) - ignored

Any idea? how can use less than in the mode above?

EDIT

I tried to flip the switch as below but worked only at positive value:

Wswitch2 no com Vcurrent negative_switch                        
.model negative_switch CSW it=1nA ih=0 ron=1n roff=1g

Best Answer

enter image description here .

As suggested earlier: first make it work in LTspice.

Short description:

  • Upper circuit contains the controlling current, which is measured by a 0V voltage source Vcurrent.
  • The circuit in the middle manipulates the current. I first read your question it should detect both positive and negative currents, hence the name "Vabscurrent" of the 0V voltage source. Make sure current source B1 is oriented correctly and the "additional circuit" is grounded as well.
    EDIT
    The middle circuit as shown is superfluous, you can simply flip the voltage source Vcurrent if you want the switch to trigger for negative currents. I leave the picture as is, as it shows you can manipulate the current to have the switch trigger to whatever condition you want.
    In case you want to have the switch trigger for positive and negative currents, you could use B1 0 N003 I=abs(I(Vcurrent)).
    You can set any condition for the switch using Arbitrary Behavioral Current Source, e.g. when a certain condition occurs after 10 seconds: B1 0 N003 I=if( time>10, if(certain condition), 1A, 0A ).
  • The lower circuit contains the current controlled switch (CSW) which is controlled by the current through "Vabscurrent". I added a picture of the Component Attribute Editor to show the name of the voltage source should be entered in the Spicemodel line.

After implementing it in LTspice, read the netlist and use/compare it to the netlist you wrote in ngspice.

W1 N005 0 Vabscurrent MySwitch
R1 N005 N004 10
V1 N004 0 5
R2 N001 N002 R={1k-100*time+1k}
Vabscurrent N003 0 0
V2 N001 0 5
B1 0 N003 I=-I(Vcurrent)
Vcurrent N002 0 0
.tran 10
.model MySwitch CSW(Ron=.1 Roff=1Meg It=4m Ih=-.5m)
.backanno
.end