News for hackers. Stuff that matters.
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by userbinator on Wednesday June 06, 2018 @10:22PM (#17252763)
It looks nice and easy to use but I can't seem to get something as basic as a two-NOR flip-flop to work:

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.

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by travelingmaker on Thursday June 07, 2018 @06:44AM (#17254719)
For pedantic reasons, the circuit posted is still technically invalid, since the output is undefined when both inputs are 1. But yes, the simulator does have trouble with this time dependent response.
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by userbinator on Thursday June 07, 2018 @07:10AM (#17254794)
When both inputs are 1, both outputs are 0. This is a valid condition and follows from the behaviour of NOR (if any input is 1, the output is 0.)
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by satu0king on Wednesday June 06, 2018 @11:38PM (#17253067)
Please look at the examples to see what the simulator engine is capable off. As for designing the simulator engine to solve these kind of cyclic circuits, and advice on how to do it?
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by userbinator on Thursday June 07, 2018 @12:09AM (#17253207)
As for designing the simulator engine to solve these kind of cyclic circuits, and advice on how to do it?

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...

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by satu0king on Friday June 08, 2018 @03:39PM (#17269014)
Thank you! Not sure if this is within my ability to implement but will give a definite try
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by amelius on Thursday June 07, 2018 @08:03AM (#17255036)
You probably have to model the fact that gates need time to change their output. You can use a data-structure like this ([1]) to keep an ordered list of events (ordered by the virtual time), and you just work your way down the list, generating new events, until the network is stable.

[1] https://en.wikipedia.org/wiki/Priority_queue

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by satu0king on Wednesday June 06, 2018 @11:32PM (#17253037)
Yes, the storage loop doesn't work yet. However you can simply use a d-flipflop to do what you need.
Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by userbinator on Thursday June 07, 2018 @12:12AM (#17253221)
However you can simply use a d-flipflop to do what you need.

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.

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by bjackman on Thursday June 07, 2018 @11:30AM (#17256666)
If you have a flip-flop atom then you can do some meaningful stuff; IIRC the gate-level circuit simulator that the Nand To Tetris course uses can't handle this stuff, and you can still build a CPU. I guess it just depends at what level you want to think about the circuit.

Edit: maybe it should be called a "logic circuit" instead of a "digital circuit".

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by satu0king on Thursday June 07, 2018 @12:32PM (#17257422)
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 :)

Re:Show HN: CircuitVerse – Online Digital Circuit Simulator by ansible on Thursday June 07, 2018 @12:22PM (#17257283)
Yeah, I saw 'timing' mentioned, and also tried to create a flip-flop for yucks.