[SOLVED] Switch settings simulation

Hello everyone, another problem with the simulation. I would like to simulate switching a switch to see the phase change on a circuit with an OPAMP. I have defined a sinusoidal input generator at 1Khz and 50mV signal V1. On the negative input of the OPAmp I want to simulate the grounding via the SW1 here is the diagram:


I tried to add the .model line but it doesn’t change anything! (Now is comment by #)
Here the out simulation :

the I get an error message I don’t understand :
Msg
Thanks to help !
Vincent.

Eeschema sends
vsw1 sw vm cmd vm switch
to ngspice.
This is wrong because the first letter v tell ngspice to add a voltage source (instead of a switch). The correct line would be
sw1 sw vm cmd vm switch
(without the leading v). A reason might be the switch symbol selected. It looks like a manually actuated switch, not a relay (electrically driven switch like the ngspice ones).

I have made my own generic relay symbol for this purpose. At least you should try the following: Double click on the switch symbol. There is an entry in the line ‘Reference’. Change it to Sw.

Hello holger and thanks for the suggestion, unfortunately there is no relay on my diagram, SW1 is a double switch named SW1. Are you saying it would be better to replace it with a relay? The coil on the V2 pulse generator?

See edit above.

Yes, because you want to have a voltage controlled switch (aka a relay), not a manually actuated double pole single throw switch. But still you have to take care that the Reference name of the new symbol starts with an S (not a V, not a K …).

Ok, Not sure to understand the subtlety!
New schematic :


same type of warning message :
Msg2

As ngspice says, there is no model.
You have to add:
.model ADW11 SW (Ron=1m Roff=1G Vt=2.5 )
and you have to change the node sequence:
Double click onto the symbol->Edit Spice Model->Check box ‘alternate node sequence’-> add node sequence
3 5 1 6
into the text field right to the box.

If this does not work, please post your *sch file.

Thanks holger, I add .model and modify pins sequence without change.
The schematic file :
Phase.sch (8.1 KB)
TLO72 lib :
TL072.lib (1.1 KB)

Things become more complex.

KiCAD 5.1.9 does not accept a switch as a standard model. Therefore the assignment of an alternate node sequence has not been successful. The simulation runs, but due to wrong nodes in the switch (as one can see by having a look at the nespice Netlist) is not o.k.

The only way is to define a subcircuit model which contains the switch. This model then has to be assigned to the switch symbol. I will make a suggestion by tomorrow.

1 Like

Attached you will find what I have got so far.Vidalv.zip (9.1 KB)

1 Like

There is still a bug in my zip file.

The model for the switch has to be
.model ADW11 SW (Ron=1m Roff=1g Vt=0.25)
because the switch input differential voltage is between 0 and 0.5 V.

1 Like

Hello Holger thank you for your help.
I understand the principle better now.
It is therefore necessary to define a sub-circuit (quadric-pole here) via the relay S1 with the parameters as well as the Alternate node sequence:


Then, add a .model with the contact characteristics:
.model ADW11 SW (Ron = 1m Roff = 1g Vt = 0.25)

By adjusting values :


Result:

Thanks a lot for your support ! :smiley:

Vincent.

Hello Holger, I would like to thank you for your support on the spice simulation.
I think that this artifice must be exploitable for other configurations of simulations (probably !).
Although the documentation is complete and downloadable here:
http://ngspice.sourceforge.net/docs.html
It is nevertheless quite difficult to understand, the examples remain sufficient but rudimentary.

Here table for model type :


Thanks again for the support!
Vincent.