Digital-Logic-Sim icon indicating copy to clipboard operation
Digital-Logic-Sim copied to clipboard

0 and 1 fixed constants, and convergence fix

Open Acidification opened this issue 4 years ago • 2 comments

When creating a chip that you require, for instance, a constant 1 input, (e.g. increment by 1, for the program counter) it would be nice to have it inside the chip, and not providing it from the outside. After all, this is a logic sim, we aren't supposed to give the "power and ground" (Metaphorical, don't kill me in comments) Also, trying to create a chip with a not gate inside not connected to anything causes the chip to not work at all, prob. due to some convergence error.

For this last point, the program could simply deny the creation of new CIs without all wires connected, with will be possible if the constants are added.

Acidification avatar Dec 29 '20 16:12 Acidification

Chip not working at all: https://gyazo.com/17ac3c4fb3e6000df8f14ac8e24cf794 Wiring: https://gyazo.com/731c19e0b373065dbb2fbd07d15588cd

Possible solution: Wire ANY of the inputs to this blocks* to create constant 1 and constant 0. We just have to agree, it looks ugly and use more computational power then needed. *https://gyazo.com/5304f12c8e20eb99c5e911493152ef53

Acidification avatar Dec 29 '20 16:12 Acidification

The issue rises from an optimization, the updating of signals isn't checked every frame for every pin, rather it's only updated when an output signal changes (or an input pin) and by default, all pins are 0. When a chip is added to the current workspace, all the pins are set to 0, and any input pins can ripple inside the chip. As such, a non-native constant needs some input.

Using this knowledge, here is a constant 0 An input pin connecting to a NOT gate and an AND gate, the NOT gate connects to the other input of the AND gate, making sure the output of the AND gate is always off, which connects to the output

With this, you can invert it to get a constant 1 An input pin connecting to a chip named 0, which has the circuitry in the image above, then connecting to a NOT gate which connects to an output

Both of these work as expected An image showing chips named 0 and 1 output the signal 0 and 1, respectively

You need to somehow connect these inputs to a top-level input, otherwise they will never be updated, and cause the same kind of non-fatal input you experienced when sending any input to a NOT gate. This also applies to connecting a constant into a constant. You need it to some chip that does NOT use a constant. In an actual circuit, you can just connect it to some input directly, it doesn't need a dedicated input.

Here is an example of a NOT gate, even though these is one built in (and this circuit does use them a couple times deep down) An input pin outputting 0 to a constant 1 and an XOR gate, the 1 output connects to the other XOR input, the output of the XOR gate connects to an output pin with the value 1 Exactly the same as above, except the input pin outputs 1, which doesn't change the constant 1 but makes the XOR output 0, like a NOT gate

This image demonstrates the constants do not break all circuitry, and don't need a dedicated dummy pin An input pin with 0 connecting to a chip named NOT 2, containing the circuit above, which outputs 1, and an input pin with 1 connecting to another NOT 2 chip, which outputs 0, identical in behavior to a NOT gate

sodiboo avatar Jan 04 '21 02:01 sodiboo