Redstone circuits/Memory

Latches and flip-flops are effectively 1-bit memory cells. They allow circuits to store data and deliver it at a later time, rather than acting only on the inputs at the time they are given. Functions using these components can be built to give different outputs in subsequent executions even if the inputs don't change, and so circuits using them are referred to as "sequential logic". They allow for the design of counters, long-term clocks, and complex memory systems, which cannot be created with combinatorial logic gates alone.

The common feature at the heart of every Redstone latch or flip-flop is the RS NOR latch, built from two NOR gates whose inputs and outputs are connected in a loop (see below). The basic NOR latch's symmetry makes the choice of which state represents 'set' an arbitrary decision, at least until additional logic is attached to form more complex devices. Latches usually have two inputs, a 'set' input and a 'reset' input, used to control the value that is stored, while flip-flops tend to wrap additional logic around a latch to make it behave in different ways.

RS NOR Latch & Input-Stabilizers


A device where Q will stay on forever after input is received by S. Q can be turned off again by a signal received by R.

One useful feature of the RS NOR is that it can turn an impulse into a constant redstone signal, similar to a lever in the "On" position. This can be done with separate locations for the On and Off buttons/plates/trip wires and mixed signal length circuits, unlike a lever.

This is probably the smallest memory device that is possible to make in Minecraft. Note that Q̅ means the opposite of Q, e.g. when Q is on, Q̅ is off and vice-versa. This means that in certain cases, you can get rid of a NOT gate by simply picking the Q̅ output instead of putting a NOT gate after the Q output.

A very basic example of use would be making an alarm system in which a warning light would stay turned on after a pressure plate is pressed, until a reset button is hit. Or a train track switch with Q and Q̅ being detector rail.

In the truth table, S=1, R=1 is often referred to as forbidden, because it breaks the inverse relationship between Q and Q̅. Also, some designs where the input is not isolated from the output, such as B and D, will actually result in Q and Q̅ both apparently being 1 in this case. As soon as either S or R becomes 0, the output will be correct again. However, if S and R both become 0 on exactly the same tick, the resulting state could be either Q or Q̅, depending on quirks of game mechanics. In practice, this input state should be avoided because its output is undefined. In design E, S=1 and R=1 results in both Q=0 and Q̅=0.

Along with traditional Redstone designs, an RS-NOR latch can also be achieved with a Sticky Piston. If a repeater is connected into itself, and given power, the power is maintained until the circuit is disconnected. If a Sticky Piston is positioned with a block to cut off power, it can be connected to the R input and reset it. This method is much simpler than traditional Redstone designs, but takes up somewhat more space. A more compact version of this type of RS-NOR latch can be constructed as of Minecraft 1.0, taking up either a 2x5x2 space if the piston remains on the level of circuitry, or 2x3x4 space if it is placed vertically.

Note that designs H, J, and K only have a Q output, and no Q̅. Design H is vertically oriented and is shown from the side.

On another note, you can make an RS NOR Latch disable itself any number of ticks after the RS NOR Latch is true. Split the output redstone path into 2 parts and then place Repeaters on the second path. Lead the second path in to the input that will turn off the Latch. When you turn on the Latch, the redstone will turn off the Latch. This is good for timed parkour jumps.

Enable/Disable RS NOR latch
This can be made by having AND gates on the inputs, and connecting both AND gates to a third input, E. If E is true, the memory cell works as normal. If E is false, the memory cell will not change state.

Input-Stabilizing Cell


This device will stabilize an input once received even after the input source stops. It is essentially a non-resettable RS-NOR Latch where a repeater powers itself. For example a stone button or pressure plate signal could be turned into a permanent power source with one push. This device can be turned into an RS NOR latch with the addition of two sequential NOT gates (torches) along the top row. When the second (right hand) torch is powered, the state returns to 0. This can also be achieved with a piston. They are useful for traps where the trapped player has to stand on a pressure plate or button as they can't be reset. The simplest solution to reset this circuit is to attach a block to a sticky piston in and have it extended on a NOT gate right behind the repeater. Since blocks carry a redstone signal, the circuit will function until a shutoff wire is tripped and the piston retracts. This can also be placed on an oscillator so that instead of acting like a shutoff, it acts as a reset.

RS NAND Latch
Since NOR and NAND are the universal logic gates, a design for an RS NAND latch is just an RS NOR with inverters applied to the inputs and outputs. The RS NAND is logically equivalent to the RS NOR as the same inputs for R and S give the same outputs. This circuit is impractical in Minecraft because a single Redstone torch acts as a NOR gate.

When S and R are both off, Q and Q are on. When S is on, but R is off, Q will be on. When R is on, but S is off, Q will be on. When S and R are both on, it does not change Q and Q. They will be the same as they were before S and R were both turned on.

D Flip-Flop & Gated D Latch
A D flip-flop, or "data" flip-flop, sets the output to D only when its clock input transitions from OFF to ON (positive edge) or ON to OFF (negative edge). A flip flop is said to be an edge triggered device, while a gated latch is a level triggered device (triggered on either an OFF or ON clock/enable input). The basic level-triggering gated D latch (design A) sets the output to D as long as the clock is set to OFF, and ignores changes in D as long as the clock is ON. However, on a positive clock edge, if D is low, the output will pulse high for 1 tick, before latching low.

You can often turn a gated D latch into a D flip flop by including an edge trigger. Design B includes a positive edge trigger and it will set the output to D only when the clock goes from OFF to ON.

In these designs, the output is not isolated; this allows for asynchronous R and S inputs (which override the clock and force a certain output state). To get an isolated output, instead of using Q simply connect an inverter to Q.

Design C is a one block wide version of A, except for using a non-inverted clock. It sets the output to D as long as the clock is ON (turning the torch off). This design can be repeated in parallel every other block, giving it a much smaller footprint, equal to the minimum spacing of parallel data lines (when not using a "cable"). A clock signal can be distributed to all of them with a wire running perpendicularly under the data lines, allowing multiple flip-flops to share a single edge-trigger if desired. The output Q is most easily accessed in the reverse direction, toward the source of input. Q can be inverted or repeated to isolate the latch's Set line (the unisolated Q and Q wires can do double duty as R and S inputs, as in design A).

Design E provides a more compact version of A, while still affording the same ceiling requirement. E' allows the edge trigger to act on a high input. Design F holds its state while the clock is high, and switches to D when the clock falls low. The repeater serves to synchronize the signals that switch out the loop and switch in D. It must be set to 1 to match the effect of the torch.

Design G employs new repeater mechanics which were added to the game as of snapshot 12w42a. It holds its state while the clock is high, and is by far the most compact of the D latch designs. Design H combines two G latches, one positive and one negative triggered, to create a positive edge-triggered flip-flop. The block and redstone torch can be reversed for a negative edge-triggered design.

BUD based D Flip-flop
Someone discovered a brand-new design of D flip-flop by applying the principle of Block Update Detector. This flip-flop is small so it can be used multiple times at large integrated redstone circuits. Note that when building, all block that's adjacent to the piston cannot be used as circuit components except flip-flop itself.

The lever in the screenshot shown is an example of D input. Redstone wire in the middle is trigger signal input. The trapdoor is just a part of the BUD so it can be replaced by a fence door, a redstone lamp, etc.

JK Flip-Flop & Latch
A JK flip-flop is another memory element which, like the D flip-flop, will only change its output state when the clock signal C changes from 0 to 1 xor 1 to 0 (edge-triggered, design A and B), or while it holds a certain value (level-triggered latch, design C). When the flip-flop is triggered, if the input J = 1 and the input K = 0, the output Q = 1. When J = 0 and K = 1, the output Q = 0. If both J and K are 0, then the JK flip-flop maintains its previous state. If both are 1, the output will complement itself — i.e., if Q = 1 before the clock trigger, Q = 0 afterwards. The below table summarizes these states — note that Q(t) is the new state after the trigger, while Q(t-1) represents the state before the trigger.

The JK flip-flop's complement function (when J and K are 1) is only meaningful with edge-triggered JK flip-flops, as it's an instantaneous trigger condition. With level-triggered flip-flops (e.g. design C), maintaining the clock signal at 1 for too long causes a race condition on the output. Although this race condition is not fast enough to cause the torches to burn out, it makes the complement function unreliable for level-triggered flip-flops.

Design E is a vertical JK Flip-Flop from the basis of design A. This circuit can be built together in series side-by-side by spacing the circuit one block apart and alternating the direction of the circuit (left-to-right, right-to-left, etc.). By adding an AND gate combining K and Q at the end of this circuit and outputting the result into the inputs J and K of the next gate you can get a binary counter. For optimal space saving you can pass input K through the block it hits by replacing the Redstone wire with a relay. Then you can just add additional Redstone wire on the other side to bring the input of K over to Q. There is also enough space to begin a vertical AND gate to where the result is just to the right of output Q.

T Flip-Flop
T flip-flops are also known as "toggles." Whenever T changes from OFF to ON, the output will toggle its state. A useful way to use T flip-flops in Minecraft could for example be a button connected to the input. When you press the button the output toggles (a door opens or closes), and does not toggle back when the button pops out. (Design D does not have an incorporated edge trigger and will toggle multiple times unless the input is passed through one first.) It is also the core of all binary counters and clocks, as it functions as a "period doubler", turning two input pulses in.

Design B is slightly unreliable for very long pulses; when the input is on, the piston will toggle every time the block below the piston arm is updated.

Designs L2, L3, and L4 rely on the redstone repeater locking mechanic introduced in version 1.4.2. L3 is compact, but slower than L2. L4 is the smallest, but requires a piston. It activates on a falling edge.

The compact T flip flop is good for having many in a row, which might be useful for compact redstone circuitry of traps, combo codes, etc. It demostrates the use of a simple monostable circuit that immediately blocks the 10 or so tick signal of the button as soon as a 1-tick signal has passed through to the repeater. Then, the sticky piston will either pull or push away the block over or away from a redstone torch, which then can power that block and give a signal to the lamp.

Rail T Flip-Flop
The Rail T flip-flop is a T flip-flop which uses rails and Redstone. It is slower than traditional Redstone-only circuits, but this may be desirable in certain situations. The wooden squares at the rail corners are pressure plates that will switch the conventional RS-NOR latch at the bottom.