Friday 7 February 2014

ngspice - How to simulate simple on/off, Single-Pole-Single-Throw switch?


I am trying to simulate ON, OFF switch in this simple circuit:


V1 0 1 1.5v
Rfan1 3 4 1
S1 1 4 SW ON
Rwire1 6 5 0.00001
VV1 0 2 dc 0
VRfan1 3 5 dc 0

VRwire1 2 6 dc 0
.dc V1 1.5 1.5 1
.print dc i(VV1) i(VRfan1) i(VRwire1)
.end

but I got this error:


ngspice stopped due to error, no simulation run!

the circuit I am trying to simulate is like this one:


enter image description here



if I replace the switch with a resistor, the circuit will work normally.


any idea? EDIT


I have fixed my switch as the following:


S1 1 4 98 99 mySwitch ON
.model mySwitch SW vt=0 vh=1 ron=1n roff=10k

Answer



I get the error:



Error on line 3 :
s1 1 4 sw on

Unable to find definition of model - default assumed



The definition of your switch is incorrect.
It should be of the type SXXXXXXX N+ N- NC+ NC- MODEL . You should:



  • define the controls NC+ and NC-

  • define the model (which has the name reserved name SW in your case) by using either .model mySwitch CSW(...) or .model mySwitch CSW(...)

  • not using the name SW as it is reserved as said above (I think that's why it crashes).


So, using the fictional nodes 98 and 99 that control the switch:

s1 1 4 98 99 mySwitch on
.model mySwitch SW vt=1 vh=0.2 ron=10u roff=1G


Do read the manual, section 3.2.14 Switches and 3.2.15 Switch Model (SW/CSW).




In addition to Sorenp's answer, you can also implement the switch by making the value of Rwire1 conditional:
Rwire1 6 5 R={if(time<2,1G,if(time>3,1G,10u))}
Between time is 2 seconds and 3 seconds, Rwire1 has its original value. Before and beyond these time stemps the resistance is 1 GΩ.


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...