Show HN: CircuitVerse – Online Digital Circuit Simulator
circuitverse.org
circuitverse.org
https://i.imgur.com/V6yXpMl.png
The gates themselves in isolation work fine, but connecting them together doesn't. I even tried "bootstrapping" the circuit by breaking the storage loop and setting the two gates' inputs so they're all consistent first before connecting them together, but then when I disconnect the bootstraps it immediately returns to the above arrangement.
IMHO having trouble with something like that means the simulation engine is not quite usable yet...
Edit: the above circuit works fine in Logisim. Also, as another minor tangent, I think the flip-flop is so much easier to understand when it's drawn to emphasise the storage loop, i.e. the two NORs essentially become inverters when one of their inputs is 0, and they act in positive feedback to hold the bit value; why almost every other diagram insists on crossing the wires is perplexing, since it only serves to confuse and complicate.
The point of my exercise was to test a basic functionality. If you cannot simulate that, the feedback loops which arise naturally in more complex circuit designs won't work either. It's like the "fizzbuzz" of logic simulation.
Edit: maybe it should be called a "logic circuit" instead of a "digital circuit".
I will take this advice and discuss with my mentors, Thank you :)
The general idea is to iterate while changes are still propagating through the circuit; here's some pseudocode:
changedNets.add(initial stimulus)
for each net in changedNets
changedNets.remove(net)
for each node in nodes(net)
for each output in outputs(node)
evaluate output
if output changed
changedNets.add(output)
if state cycle detected
break
The above algorithm reasonably accurately models what happens in a real digital circuit: changes propagate through each node until the whole circuit reaches a steady state. You can even add visualisations to show each step of the propagation as it takes place, and more elaborate versions can take into account different propagation delays (i.e. the output of each node can change at a different time relative to its input, so you process them in a queue ordered by that.)To use my example circuit, with both inputs low initially: when one of the inputs of one NOR is set high, in the next step the output goes low, then the other NOR's output goes high, and the input of the first NOR goes high. This doesn't change anything else, so the circuit reaches equilibrium. When you set that input back down, the NOR already has the other input high, so it doesn't change state and equilibrium is already reached.
Cycle detection can be as simple as a hardcoded iteration count, or something a bit more accurate and useful:
https://en.wikipedia.org/wiki/Cycle_detection
Interesting fact: A true cycle-detection algorithm will theoretically let you simulate a whole CPU running any Turing-complete program, if you clock it with an "inherently unstable" ring oscillator...
Even if the components model aren't very sophisticated, everycircuit can do full analog simulations.
If you use chrome, you can run everycircuit in-browser, then try this example: http://everycircuit.com/circuit/4709435733180416/infinite-no....
Circuitverse, as far as I can tell is just a logic simulator, which - from reading the comments - doesn't handle feedback loops.
1. Let the user change the background, and add letters/text.
2. Ability to add sound effects
3. Rube golberg style components that could be triggered by the circuit.
4. Render/Simulate real leds.
5. Add a gallery ... do you have a gallery of circuits others created?
6. Also, if you could save and output a video file of the circuit. It would make it easier to include for things like youtube videos, and possibly do animated logos and marquees using this simulator.
When you model by hand you typically use ideal models. SPICE models can be vastly more complex. A good example is a diode which is harder to model as it's a non-linear device.
Simulated "electricity" (voltage and current) is reduced to a set of differential equations, which the program then uses to plot charts.
https://en.wikipedia.org/wiki/Discrete_event_simulation
If you model a circuit in CircuitVerse, how similar would the results be to a real-world version?
As long as the gate delays and fanin/fanout are considered, the results would be logically valid. For simulation of more analogue effects (e.g. what happens if you connect the outputs of two gates together, and one tries to pull it high and the other low?) something like SPICE is necessary:
https://en.wikipedia.org/wiki/SPICE
...and since that involves numerical solutions to nonlinear differential equations, is at least an order of magnitude slower.
https://www.circuitlab.com/editor/53xa3r/
The simulation loop is both event driven (when CLK1 flips state every 0.5 seconds), propagating those changes through combinatorial gates, and analog, simulating the op-amp to create a simple digital-to-analog converter (DAC). Bridging the analog and digital sides within the simulator is tricky, but not impossible.
You are correct that if there were not both event-driven and analog simulation intermixed, and we simply simulated all the digital gates with their analog implementations in MOSFETs, that simulation would be at least an order of magnitude slower -- probably far worse!
(Disclosure: I built CircuitLab's simulation engine.)