sharpie7 / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
2.23k stars 619 forks source link

subcircuits with 2-terminal voltage sources don't work #943

Open arashhabibi opened 1 month ago

arashhabibi commented 1 month ago

Good evening, I am a computer science teacher and I would like to use your great applet for next year's electronic course at the Strasbourg University in France. I am trying to make subcircuits, and I don't understand whether I should include a ground inside the subcircuit or if I should have a ground pin that the subcircuit user connects to the ground outside the subcircuit. Example 1 : this circuit :

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgoqoQFMBaMMAKADMQAWbFEXTioSr8+vMNCQxIKFgCdBVMBkIKQKPHijJ4LAO6qetIXzwDIe1es2EUAq1BZpy3XiJdqEKgQDUAlgDtHSHIbOw0QUI8vEG8AewBXABcWADcuYhVsU3SVJRUqKk5aLQKJC04MkwFPYWzzfQrc5VU8hwbKrIF3TocnLh4q-tdsaIBxABMWIA

has no ground. When I try to make a subcircuit out of it, the "File/Create subcircuit" does not complain. But it is impossible to include this subcircuit in another circuit. But if I remove the Gnd label and replace it with a real ground inside the subcircuit, then the it can be included inside other circuits without any problem.

Example 2 : this other circuit :

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxATwosgoFMBaMMAKADNkUAWELsQ5Hip8B2FOGhIYkFOxB5CPEfLi9+IMRKmxZAJ0FVs2AWHxUUCAbVNwW+vKqMCHtC1eS2A7iteWDINygWbzxiUWMQUnFlSGDI4nEneTC1KzjQgWUFJXVY-SiNCNMhQvcbO2Tw50cI6y8QHAFAlwC-WO8C5VNuVKCQmuraLlV2-yTi4RG4idLwFHUk0YQuHkDG1rSOPE0uB3lFXj3NMEkoaFkQg6yrg9iOAoQwcW6eR8Tn09RpmRyTH94UqMZlxjmYQIQMOJRi0QeIWhCoXJtuJLLRshRCLRjp9znIHglOK8CdjtHoGhE1hFsAgoR47g1IDxCD11syeCSzhdyQI3tzwfg+vslCl0cseED-jSqC8KBg0pdXnKheDIYKZZjpf8EYLWcM+drRqzVfDVdDVNr0Qb0gdterTd8erawVbvGLeOa9cNaKNFLQ2QymT1DVSaXzdt64utw3zedDNKj+VQE6N8eINRQCT6BQgCenk3E85jE4cI9509G3dG49E9lG9imCbzfRQnoLm17wXrYwWu63m-7YmhyG7AiOBTwAGoAYynLCHFBWJYXSh2IAAwgAbADWc8gw8XHbd1OiIAnAEsAHa78hPBZFeZNEqTgD2AFcAC6RiLat1W+e-1Vfx6HgAHEABMWCAA

has no ground either, but unlike the first circuit, I have no problem making a subcircuit and including it in other circuits.

I think I am missing something. Which is the correct workflow in falstad ?

Any help/explanations would be welcome

Yours

AH

pfalstad commented 1 month ago

There's a bug in the simulator that causes the first circuit to not work. It's throwing an exception, which is handled and ignored, so that's why nothing happens.

The problem is the 2-terminal voltage source. It doesn't work in subcircuits because of a bug.

You can work around the issue by doing the following:

  1. create a ground node like so: https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgoqoQFMBaMMAKADMQAWbFEXTioSr8+vMNCQxIKFgCdBVMBkIKQKPHijJ4LAO6qetIXzwDIe1es2EUAq1BZpy3XiJdqEKgQDUAlgDtHSHIbOw0QUI8vEG8AewBXABcWADcuYhVsU3SVJRUqKk5aLQKJC04MkwFPYWzzfQrc5VU8hwbKrIF3TocnLh4q-tdsaIBxABMWAHM1DF5bKkx5uZKWIA

  2. select everything except the ground

  3. create subcircuit

arashhabibi commented 1 month ago

Thank you very much for your rapid and efficient reply. Everything works now. So I must remember : all circuits yielding a subcircuit must contain a ground, even if, when making the subcircuit, we choose not to include the ground in the subcircuit. I also must remember to use 1-terminal voltage sources in subcircuits. All the best, and thank you for your great app ! AH

pfalstad commented 1 month ago

reopening this so I remember to fix the bug