Cannot figure out how to create logic circuit with a few input variables...

Hi,

I really like the idea of being simulate DC circuit within a web browser. However, I have been stuck for a few hours now trying to figure out how to use a switch to give my variable a meaning of digital 1 or 0.

I tried various switches, with either "digital 1" or voltage source as input, and on the other side, I gave name nodes "X1" and "X1 not". I would like to have a simple switch, such that when I toggle "X1", it will toggle "X1 not" as well.

Ultimately, I will feed X1 and X1 not to my "OR" "AND" combination logic to test my final output using DC analysis.

Can someone please point to an example?

Sincerely,

Patrick

by pcit
May 26, 2013

Without an example circuit to look at, it's unclear exactly what you would like to do but here are some pointers that may help:

About Switches

How to simulate opening or closing a switch so that you don’t have to go back and forth between build and simulate modes to see the circuit operation in both states.

How do you model or display a power jack of the sort that when plugging into this jack switches or reroutes a voltage?

There are at least 3 ways to do this.

i) You can do sims with swept parameters where the swept parameter is the switch state.

ii) Or use the time controlled switch.

iii) Or use the voltage controlled switch (driven by a suitable pulse source).

This thread gives some more information about these techniques:

https://www.circuitlab.com/forums/modeling-and-simulation/topic/v476bfdj/is-there-a-model-for-a-male-power-jack/

A simple 'ON if the power is plugged in or OFF if it is not' jack can be represented by a normally open (SPST no) switch.

It could equally be represented by a normally closed (SPST nc) switch if the power is normally plugged in.

The sort of jack that physically reconnects between say an internal battery and an external supply can be represented by a changeover switch (SPDT).

i) You can use any of the CL switches and draw a box round it with some text to explain what it represents;

ii) if you use the 'static' switches as shown in:

https://www.circuitlab.com/circuit/2xpye8/

then in one run, you can simulate the circuit once with the switch open and once with the switch closed.

However, note that if you use the static changeover switches like the SPDT shown in:

https://www.circuitlab.com/circuit/954hs2/

then you cannot see the results of the A switch closed (B open) and then the B switch closed (A open) in one simulation run because you cannot select the switch state as a sweepable parameter. You have to do two simulation runs which is a bit naff.

iii) if you use the time controlled SPDT switch then you can simulate how the circuit behaves with the switch in the before the changeover state and then in the after the changeover state;

iv) you can use two voltage controlled switches driven by a PWS() or PWSREPEAT() source to make an SPDT switch which you can switch any time you like:

https://www.circuitlab.com/circuit/d66f6n/

(see:

https://www.circuitlab.com/docs/expressions/

and

https://www.circuitlab.com/docs/circuit-elements/#behavioralsources

for more about the PWS() source)

Note that it is not clearly documented but switches in CL do not have an infinite OFF state resistance. This can lead to unexpected results. For example, a DC plot of this circuit:

https://www.circuitlab.com/circuit/586t3d/voltage-controlled-switch-off-state-resistance-01/

with R1 removed from the circuit would show V(output) = 1V.

Here's why.

The resistance to ground at the Output node is infinite because it is an open circuit.

However, the switches in CL are not ideal. They have a very large but finite OFF resistance.

Therefore when operating into an open circuit load there would be no difference between the ON and OFF state voltages at the Output node.

The example demonstrates this using a DC Sweep probing V(output) with a Decade Sweep of the value of R1 (R1.R) from 1e12 to 1e18 at 10 points/Decade.

It can be seen that V(Output) = 0.5V when R1.R is equal to around 1e15 Ohms.

This is the undocumented OFF state resistance of the CL voltage controlled switch.

Note that if a CL voltmeter were to be connected in place of R1 then there would be a clear ON/OFF state difference because the CL Voltmeter has a user definable finite resistance with a default value of 1G.

Also:

https://www.circuitlab.com/circuit/kzw5km/mosfet-cmos-nor-gate/

https://www.circuitlab.com/circuit/592d96/mosfet-cmos-nand-gate/

https://www.circuitlab.com/circuit/zjc468/mosfet-and-resistor-nor-gate/

https://www.circuitlab.com/circuit/zjc468/mosfet-and-resistor-nor-gate/

and replace the MOSFETs with voltage controlled switches a bit like this:

https://www.circuitlab.com/circuit/bdp4kn/open-collector-comparator-using-switch/

which can be seen as a logic inverter stage.

by signality
May 26, 2013

Post a Reply

Please sign in or create an account to comment.

Go Ad-Free. Activate your CircuitLab membership. No more ads. Save unlimited circuits. Run unlimited simulations.

About CircuitLab

CircuitLab is an in-browser schematic capture and circuit simulation software tool to help you rapidly design and analyze analog and digital electronics systems.