1
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ Could you try making a switch for positive current and connecting it backwards? \$\endgroup\$ – user253751 Aug 19 '19 at 4:26
  • \$\begingroup\$ No, it did not work, kindly check EDIT above \$\endgroup\$ – simo Aug 19 '19 at 4:33
  • 1
    \$\begingroup\$ @Simo Of course flipping the switch contacts/nodes will make no difference. You should flip the controlling part, so Vcurrent. \$\endgroup\$ – Huisman Aug 19 '19 at 6:10
  • \$\begingroup\$ I need to keep the controlling part as is, as controlling part might be positive or negative, it's not fixed \$\endgroup\$ – simo Aug 19 '19 at 6:14
2
\$\begingroup\$

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
\$\endgroup\$
7
  • \$\begingroup\$ Thanks for thoughtful answer \$\endgroup\$ – simo Aug 19 '19 at 19:38
  • \$\begingroup\$ How can I print in ngspice the current state of a switch? ex: opened or closed? can I print resistance between two nodes? ex: nodes of the switch \$\endgroup\$ – simo Aug 20 '19 at 22:53
  • \$\begingroup\$ I tried to print current as .print dc i(Vabscurrent), I got Warning: can't parse 'Vabscurrent#branch': ignored Error(parse.c--checkvalid): Vabscurrent#branch: no such vector., is this because I tried to print inside SUBCKT ? \$\endgroup\$ – simo Aug 21 '19 at 3:04
  • \$\begingroup\$ I would think you need to address it like i(V.x1.Vabscurrent) or so. But make a subcircuit in LTspice and find out... \$\endgroup\$ – Huisman Aug 21 '19 at 5:50
  • \$\begingroup\$ @simo You need to explicitely save data from the subcircuits. Section 17.5.61 of the manual: save may store data from nodes or devices residing inside of a subcircuit So, you need to add: save i(V.x1.Vabscurrent) or save V.x1.Vabscurrent#branch. In the examples in the manual they use multiple instances of x1, no idea why (maybe sub-sub-subcircuit?). Anyway, if it fails, you may try save i(V.x1.x1.x1.Vabscurrent) \$\endgroup\$ – Huisman Aug 22 '19 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.