Traditional Verses Faulty Logic Lamp Based Flip-Flops (Divide by 2)

ZeroGravitas

The Destroyer
It's entirely possible in Terraria, now, to make various real world logic circuits by following circuit diagrams that use traditional electronic logic gates *. The gates manage to emulate the logic states. Here's an example of your typical "D-Type" (D stands for data) circuit (from wikipedia):
330px-Edge_triggered_D_flip_flop.svg.png

When a "clock" signal comes in (state changes to on) the logic state on the data input gets transferred to "Q" (and Q-bar is set to the opposite of that). The data is latched (or loaded) into this device's simple memory. Looping the Q-bar output back to the data input then causes the output state to flip on every other state change of the clock input. (Since this is a "positive edge" triggered setup, change to off state is ignored.)

In Terraria this NAND gate assembly functions the same and looks like this (with the long yellow wire at bottom providing the toggle feedback, not shown above):
I've tried to lay it out in the same way as the top diagram, for demonstration purposes.

However. In their infinite wisdom, the devs have provided a somewhat more compact way to achieve the same function. A kind of ultimate flip-flop, thus:
1BpDyIu.png

The output torch will change state every other time the input-switch-linked torch does. This is thanks to the "faulty logic lamp", which magically converts any logic gate into a randomizer: inputs to the faulty lamp (always top of the stack) will produce an output a percentage of the time depending on the number of regular lamps that are currently turned on. There can be many lamps stacked up in different states to tune this probability, but with only 1 lamp this means it will always relay the input signal to output when the lamp is on (100%) and never when it's off (0%). Thus by connecting both the faulty lamp (input) and the only probability-adjusting lamp together, every other input signal will be ignored as the probability function toggles between 100% and 0% (of relaying the input change signal).

Anyway, this super-simple setup makes for a very compact and effective binary counter: just a string of flip-flops, each dividing by 2.
This setup seems unbeatable - not only is it tiny and simple, it should also operate and count as fast as you can toggle the input, multiple times within a single tick(!), as the wire activation ripples through it. Bye-bye dusty, old skeleton counter!:eek:
[doublepost=1464089760,1464083723][/doublepost]To go a step further in showing the faulty lamp gate's flexibility, here's a counter with a reset line integrated and an (accidental) shifter line, all with just 1 lamp randomisers:
Their function and interactions are pretty subtle (and somewhat unintuitive, I think). The counters only count correctly if the output is inverted (i.e. the torches are in the opposite state to the gate input lamps they are connected to).

This means the reset line actually sets the count to maximum value (all torches on), as opposed to zero. But inverting the lamp inputs of the reset line did not correct this, instead this created a shifter (multiply by 2, effectively), that moves each bit of the count pattern one to the right (useful for various binary math operations). An interaction between the attempted reset and the count circuits, I guess (?).

Note: DicemanX's AND gate based reset mechanism functioned poorly when in place, here, taking repeated activations (and much smoke) to clear all the bits. (As with most things, I imagine there will be work-arounds or better designs.) ...fine, too, once setup correctly (although still produce a bunch of smoke).

sm0z34g.png

Also, regarding the " * " in the top of the post: some logic gate latch types work with Terraria wiring, while others seem to fail in certain configuration. This "gated SR latch" seems to function ok:
300px-SR_%28Clocked%29_Flip-flop_Diagram.svg.png

It transfers the logic level presented at the top or bottom inputs to the opposite position output, only when the middle switch (gate) is set to enabled.

But others I failed to make function correctly, with smoke emanating from gates due to the loop back of outputs to inputs. (Maybe I was being dumb though.)
 
Last edited:
Beautiful. I was trying to make a cross wired NOR SR latch and it was bugged out, thanks for the new configuration. On top of the wiring as always, you already found a new binary counter, and SR latch!
 
Ok, so, in his AND gate reset mechanism thread @DicemanX asked:
What I'm curious about is your claim that the reset I posted was not working for you in one of your builds.
And he was right to wonder. I hadn't recognized that the polarity on the input lamps needed to be reversed for this AND gate reset configuration, too (as with the faulty lamp made reset). Also, it didn't behave like the opposite input faulty-gate shifters because I'd tested it hastily before adding the extra auto-reset AND gate, on the end.
So the alternative setup appears to function identically in this case. However, I'm still concerned that this might not always be the case when gates smoke from get over-driven with looped-back signals. When the gates smoked in the failed latches I tried, they threw the state of the gate out of sync with the lamps it was connected to, in some situations. (I think @Chase Brower is reporting the same issue, above.)

Anyway. Wiring up the auto-reset AND gate, from the above setup, to also input an +1 count, made the reset switch the torches to all off (instead of all on - a proper reset). This feature is just as easily added to the faulty logic gate based reset mechanism:

Then I discovered that simultaneously activating all the inputs on the (count) accumulator's faulty lamps produced a complement function, inverting the binary pattern, as shown at the beginning of this Gif:

Which is handy, because when I incorporated one more line of logic for adding a binary number directly into the accumulator, I could do subtraction too, by adding a number to the accumulator, converting it to complement (blue wire bulb light lit) adding in the number to be subtracted and then switching back from complement function. Here 22 minus 7 = 15:
[Edit 2016-05-27: replaced incorrect duplicate Gif.]

Binary operations with these gates just seem to want to happen. Heh. I'm not sure of the best way to do multiplication, division or binary to BCD, but given the speed of operation of these gates, it would almost be viable to do multiplication via the very inefficient repeated addition method (and a very rapid clock cycle). This is getting off topic, deserving a separate ALU thread, but I'm just pottering about and throwing up my findings as I go, at this stage (no grand plans).
[doublepost=1464336295,1464190083][/doublepost]Ok, so just noticed that the last gif was an incorrect upload, a duplicate, not showing the arithmetic engine (add/subtract). Why didn't someone say something?! :p Fixed now (enjoy).
 
I do fancy the binary counter using the t flip flops. The only problem I have with it though, is when using the reset, it resets to the highest possible number instead of back to 0. Is there a way to make it reset to all 0's instead of all 1's?
 
I do fancy the binary counter using the t flip flops. The only problem I have with it though, is when using the reset, it resets to the highest possible number instead of back to 0. Is there a way to make it reset to all 0's instead of all 1's?
Invert your reset lamps. See also this thread, which showcases a variety of binary counters with additional functionality; in particular, this post of mine contains the most compact resettable binary counter design I've yet found.
 
Invert your reset lamps.
As I've talked about in that thread, the torches can only be in one phase relative to the counter's logic lamps: one when the lamp is darker. So you can not arbitrarily invert them to suit the reset logic, here. If you invert the torch states from what I've shown you will be counting logical 1s as off torches.

To fix:
resets to the highest
You either add an additional "+1" signal (e.g. with that AND gate to the left of the reset line, in the last Gif of mine), or, you wire the reset gates to the counter separately, such that they only connect to the torches in regular lamp, not the input (faulty) lamp too (as mine does). This requires additional wire colours, as @crawlr and @MageKing17 have shown, for example:
[doublepost=1464786981,1464786663][/doublepost]Anyway @idkwhoiam129, would you care to show your working 4 NAND gate flip-flip here? Plus any others you've made that work, and especially any types that should work, but don't (dues to loop protection code).
 
Anyway idkwhoiam129, would you care to show your working 4 NAND gate flip-flip here? Plus any others you've made that work, and especially any types that should work, but don't (dues to loop protection code).
Well, this what you have is a T Flip Flop
fb1bc74345.png
And what I've got built is a D Flip Flop
1d2c8bf119.png

Edit: also, the yellow wire is the o̅u̅t̅p̅u̅t̅
 
Back
Top Bottom