{{schematic}} if possible.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
RS NOR latch designs.
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.
Examples of use include an alarm system in which a warning light stays on after a pressure plate is activated until a reset button is pushed, or a rails T-junction being set and reset by different detector rails.
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.
Any RS-NOR latch with dual outputs is functionally symmetrical: pulsing each input turns on "its" output, and turns off the other one. In several designs (A, B, D, F, I) the functional symmetry is reflected by their physical symmetry, with each input energizing the torch it leads to, while turning off the other.
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.
| S | R | Q | Q̅ |
|---|---|---|---|
| 1 | 1 | Undefined | Undefined |
| 1 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 0 | Keep state | Keep state |
| Design | A | B | C | D | F | H | I | J | K |
|---|---|---|---|---|---|---|---|---|---|
| Size | 3x2x2 | 3x2x2 | 3x3x3 | 2x2x4 | 4x1x2 | 4x3x1 | 2x1x3 | 5x1x3 | 4x1x3 |
| Torches | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 0 |
| Redstone wire | 4 | 4 | 8 | 6 | 4 | 4 | 0 | 7 | 4 |
| Repeaters | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 1 |
| Sticky pistons | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Inputs isolated? | No | No | Yes | No | Yes | No | Yes | Yes | No |
| Outputs isolated? | Yes | Yes | No | No | Yes | Yes | Yes | Yes | No |
| Input orientation | opposite | adjacent | adjacent | opposite | opposite | opposite | opposite | perpendicular | perpendicular |
Variations on RS-NOR Latches
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 called a monostable circuit. (You can also use a more complex delay mechanism, such as a water clock.)
An "Enable/Disable RS NOR latch" can be made by adding a pair of AND gates, in front of the inputs, testing each of them againsta third input, E. Now if E is true, the memory cell works as normal. If E is false, the memory cell will not change state. That is, E latches the RS-NOR latch itself.
An "Input-Stabilizing Cell" 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.
Input Stabilization Circuit
Input Stabilization With Reset Option
RS NAND Latch
RS NAND latch designs.
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.
| S | R | Q | Q |
|---|---|---|---|
| 1 | 1 | Keep state | Keep state |
| 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 0 | 0 | Undefined | Undefined |
| Design | A | B |
|---|---|---|
| Size | 6x3x3 | 6x2x3 |
| Torches | 6 | 6 |
| Redstone | 9 | 7 |
| Input orientation | adjacent | opposite |
D Flip-Flop & Gated D Latch
A gated D latch and D flip-flop
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.
Vertically-oriented D latches
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).
Compact D latches and flip-flop
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.
| Design | A | B | C | D | E | E' | F | G | H |
|---|---|---|---|---|---|---|---|---|---|
| Size | 7x2x3 | 7x2x7 | 6x5x1 | 2x4x5 | 3x2x5 | 3x2x5 | 6x2x3 | 2x1x1 | 3x2x1 |
| Torches | 4 | 8 | 5 | 6 | 4 | 5 | 4 | 0 | 1 |
| Redstone wire | 11 | 18 | 5 | 6 | 10 | 9 | 7 | 0 | 0 |
| Repeaters | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 4 |
| Trigger | Level | Edge | Level | Level | Level | Level | Level | Level | Edge |
| Output isolated? | No | No | No | No | No | No | Yes | Yes | Yes |
| Input isolated? | Yes | Yes | C Only | Yes | Yes | Yes | No | Yes | Yes |
BUD based D Flip-flop
Piston BUD based D Flip-flop
Someone[1] 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 no blocks that are adjacent to the piston can 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
JK flip-flop designs.
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.
| J | K | Q(t) |
|---|---|---|
| 0 | 0 | Q(t-1) |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | Q(t-1) |
| Design | A | C | D | E |
|---|---|---|---|---|
| Size | 9x2x11 | 7x4x5 | 5x2x7 | 14x10x1 |
| Torches | 12 | 11 | 8 | 10 |
| Redstone | 30 | 23 | 16 | 24 |
| Repeaters | 0 | 0 | 6 | 6 |
| Accessible Q? | No | Yes | Yes | No |
| Trigger | Edge | Level | Edge | Edge |
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-Toggle Latch
T flip-flop designs
More T flip-flop designs
A compact 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", releasing one pulse for every two it receives.
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, L4 and L5 rely on the redstone repeater locking mechanic introduced in version 1.4.2. L3 is compact, but slower than L2 and suffers the same oscillating behaviour as D. L4 is the smallest, but requires a piston and activates on a falling edge. L5 has the same footprint as L3 and activates on a rising edge (same speed as L2) but is 2 blocks high.
The one-wide dual sticky-piston T flip flop is good for having many in a row, which would be useful for compact redstone circuitry of traps, combination 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
Rail T flip-flop
Another rail T flip-flop design
The Rail T flip-flop is a T flip-flop which uses rails and redstone. The general design uses a length of track that is stopped by a block at both ends. When the T flip-flop is in a stable state, the minecart is at either end of the track (depending on the state). An input pulse turns on powered rails at both ends of the track, causing the minecart to move to the other end.
Along the track, there are two separate detector elements (e.g. detector rails). These two detectors are each connected to an input of an RS NOR latch, and hence serve to translate minecart motion into a state transition. When the minecart moves, depending on its direction of motion, one detector will turn on (and off) before the other; the second detector to be hit is what determines which input of the RS NOR latch stays on last and hence what the new state of the RS NOR latch is.
The design to the left makes use of pressure plates on the inside of a turn to detect minecart motion in redstone. The design to the right uses detector rails.
This type of T flip-flop is slower than traditional redstone-only circuits, but this may be desirable in certain situations. With T flip-flop designs that are level-triggered (as opposed to clocked or edge-triggered), a long input pulse will cause the flip-flop to continuously switch state (oscillate) while the pulse is present. In pure redstone circuits, this is only limited by the redstone circuit delays, and hence a relatively short input pulse can cause several state transitions. Pure redstone T flip-flops usually include an edge-trigger or pulse-limiting circuit to the design, since the input pulse usually can't be guaranteed to be short enough without the use of that kind of circuit.
With rail-based designs, the speed at which the output can flip is limited by the time needed for the cart to move from one end of its rail to the other, which allows for a much longer pulse to be applied to a level-triggered input without needing an edge-trigger or pulse limiter circuit. However, the delay between the input pulse and the output transition is also longer.