Flip-flops - RS, RST, JK, master–slave, ripple counters, decade counters, up–down counters, serial and parallel registers
Introduction to Flip-flops
Flip-flops are fundamental building blocks in digital electronics. They are sequential logic circuits that can exist in one of two stable states, representing binary information (0 or 1). This ability to store a single bit of information makes them ideal for use in memory elements, counters, registers, and various other digital systems. Unlike combinational circuits where the output depends solely on the current input, the output of a flip-flop depends on both the current input and its previous state. This characteristic defines them as memory elements.
Flip-flops are typically constructed using logic gates such as NAND or NOR gates. They are also known as bistable multivibrators because they have two stable states and require an external trigger or clock pulse to change from one state to another. The primary function of a flip-flop is to store one bit of data. This stored bit can be accessed and modified under specific conditions.
1. RS Flip-flop
The RS flip-flop, also known as the SR flip-flop, is the most basic type of flip-flop. It has two inputs, Set (S) and Reset (R), and two outputs, typically denoted as Q and Q' (complement of Q). The Set input, when active, forces the output Q to a high state (1), and the Reset input, when active, forces the output Q to a low state (0).
Construction and Operation of RS Flip-flop (using NAND gates)
An RS flip-flop can be constructed using two cross-coupled NAND gates. Let's assume S and R are the inputs and Q and Q' are the outputs.
- If S=0, R=1: The output Q becomes 1.
- If S=1, R=0: The output Q becomes 0.
- If S=0, R=0: This is an invalid or forbidden state, as it leads to an unpredictable output. Both Q and Q' will try to become 1, which violates the definition of a flip-flop.
- If S=1, R=1: The output remains in its previous state. This is the hold state.
Truth Table for RS Flip-flop
| S | R | Q (Next State) | Q' (Next State) | Comment |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | Invalid State |
| 0 | 1 | 1 | 0 | Set State |
| 1 | 0 | 0 | 1 | Reset State |
| 1 | 1 | Qcurrent | Q'current | Hold State |
The invalid state (S=0, R=0) is a critical issue. To overcome this, variations like the clocked RS flip-flop or the JK flip-flop are used.
2. RST Flip-flop (or RS-T Flip-flop)
The RST flip-flop is an extension of the RS flip-flop that includes a third input called the "Toggle" or "T" input. The RST flip-flop is essentially an RS flip-flop with an additional circuit that prevents the invalid state (S=0, R=0).
When the T input is 0, the flip-flop behaves like a standard RS flip-flop. When T is 1, the flip-flop enters a special state. If S=0 and R=0, and T=1, the flip-flop will toggle its output state. This means if Q was 0, it becomes 1, and if Q was 1, it becomes 0.
Operation of RST Flip-flop
- T=0: Behaves as an RS flip-flop.
- T=1:
- If S=0, R=0: The output toggles.
- If S=0, R=1: The output is set (Q=1).
- If S=1, R=0: The output is reset (Q=0).
- If S=1, R=1: This is an invalid state.
The RST flip-flop is not as commonly used as the JK flip-flop because the JK flip-flop offers more versatile functionality.
3. JK Flip-flop
The JK flip-flop is a highly versatile and widely used type of flip-flop. It overcomes the limitations of the RS flip-flop, particularly the invalid state. It has two inputs, J and K, and two outputs, Q and Q'. The J input acts like the S input, and the K input acts like the R input.
Operation of JK Flip-flop
The behavior of the JK flip-flop is defined by its J and K inputs:
- If J=0, K=0: The output remains in its previous state (Hold state).
- If J=0, K=1: The output is reset to 0 (Reset state).
- If J=1, K=0: The output is set to 1 (Set state).
- If J=1, K=1: The output toggles its state (Toggle state). If Q was 0, it becomes 1. If Q was 1, it becomes 0.
Truth Table for JK Flip-flop
| J | K | Q (Next State) | Q' (Next State) | Comment |
|---|---|---|---|---|
| 0 | 0 | Qcurrent | Q'current | Hold State |
| 0 | 1 | 0 | 1 | Reset State |
| 1 | 0 | 1 | 0 | Set State |
| 1 | 1 | Q'current | Qcurrent | Toggle State |
The JK flip-flop is a universal flip-flop because it can be configured to behave like other types of flip-flops (RS, T, D) by appropriately connecting its J and K inputs.
Clocked Flip-flops
Most practical flip-flops incorporate a clock input (CLK) to synchronize their operation. The clock signal is a periodic pulse that dictates when the flip-flop should change its state. This ensures that all state changes in a digital system occur at the same time, preventing race conditions and ensuring predictable behavior.
Clocked flip-flops change their state only when the clock signal is at a specific level (level-triggered) or at a specific transition (edge-triggered).
4. Master–Slave Flip-flop
The master–slave flip-flop is a type of clocked flip-flop designed to overcome the problem of "race-around" condition that can occur in some JK flip-flop implementations, especially when the clock pulse width is too long. It consists of two flip-flops: a master flip-flop and a slave flip-flop.
Operation
The master flip-flop receives the input signals (J, K) and the clock pulse. When the clock pulse is active (e.g., high), the master flip-flop is enabled and captures the input. The slave flip-flop is connected to the output of the master flip-flop and is enabled when the clock pulse is inactive (e.g., low).
- When the clock is HIGH: The master flip-flop accepts the J and K inputs and changes its output accordingly. The slave flip-flop is disabled and holds its previous output.
- When the clock transitions from HIGH to LOW: The master flip-flop is disabled, and its output becomes stable. The slave flip-flop is enabled and takes the output from the master flip-flop, passing it to the final output (Q and Q').
This two-stage process ensures that the output only changes once per clock cycle, effectively preventing the race-around condition. However, with modern edge-triggered flip-flops, the master-slave configuration is less common.
Counters
Counters are sequential logic circuits that count the number of input clock pulses. They are essentially made up of interconnected flip-flops. The number of flip-flops determines the maximum count the counter can reach. For example, an n-bit counter can count up to 2n states.
5. Ripple Counters (Asynchronous Counters)
Ripple counters are a type of counter where the flip-flops are not synchronized by a common clock signal. Instead, the output of one flip-flop serves as the clock input for the next flip-flop. This cascading connection causes a ripple effect as the state change propagates through the counter.
Operation
In a ripple counter, the first flip-flop is triggered by the external clock pulse. Subsequent flip-flops are triggered by the output of the preceding flip-flop. This asynchronous operation means that there is a small propagation delay between the state changes of successive flip-flops.
Ripple counters can be designed as either ripple up-counters or ripple down-counters.
- Ripple Up-counter: Each flip-flop toggles its state when the output of the previous flip-flop transitions from 1 to 0.
- Ripple Down-counter: Each flip-flop toggles its state when the output of the previous flip-flop transitions from 0 to 1.
Advantages and Disadvantages
- Advantages: Simple to design and require fewer components.
- Disadvantages: The cumulative propagation delay makes them unsuitable for high-speed applications. The outputs are not simultaneously valid, leading to glitches if read during the transition period.
6. Decade Counters (Mod-10 Counters)
A decade counter is a counter that counts in base-10, meaning it cycles through 10 states before returning to its initial state. It typically counts from 0 to 9. To achieve this, a decade counter needs to have 10 distinct output states.
Design
A decade counter can be implemented using flip-flops (usually JK or T flip-flops). A 4-bit binary counter naturally counts from 0 to 15 (24 states). To make it a decade counter, we need to modify its logic to reset the count after 9.
A common method is to use a 4-bit binary counter and add feedback logic to detect when the count reaches 10 (binary 1010). When this state is detected, the counter is reset to 0. This is often achieved by using NAND gates or other logic gates to generate a reset signal based on the outputs of the flip-flops.
Example (using JK flip-flops)
A 4-bit ripple counter can be modified to function as a decade counter. The flip-flops are connected to count from 0000 to 1001. When the count reaches 1010 (binary for 10), a logic circuit detects this state and forces the counter back to 0000.
7. Up–Down Counters
Up-down counters are versatile counters that can be programmed to count either in an increasing (up) sequence or a decreasing (down) sequence. They have an additional control input, often called the Up/Down or Direction input.
Operation
The Up/Down control input determines the counting direction:
- When the Up/Down input is HIGH (or 1): The counter increments (counts up).
- When the Up/Down input is LOW (or 0): The counter decrements (counts down).
Each flip-flop in an up-down counter is typically triggered by the output of the previous flip-flop, but the connection depends on the counting direction.
- For Up Counting: The clock input of each flip-flop (except the first) is connected to the Q output of the previous flip-flop.
- For Down Counting: The clock input of each flip-flop (except the first) is connected to the Q' (complement) output of the previous flip-flop.
A logic circuit is used to select which output (Q or Q') from the previous stage is fed to the clock input of the current stage, based on the state of the Up/Down control line.
Synchronous vs. Asynchronous Up-Down Counters
Like basic ripple counters, up-down counters can also be synchronous or asynchronous. Asynchronous up-down counters suffer from the ripple effect and propagation delays. Synchronous up-down counters have all flip-flops clocked by the same clock signal, ensuring simultaneous state changes and higher speed.
Registers
Registers are collections of flip-flops used to store multiple bits of data. A register made of 'n' flip-flops can store 'n' bits of binary information. Registers are essential components in the CPU (Central Processing Unit) for holding data temporarily during operations, such as storing instructions, memory addresses, or intermediate results.
8. Serial and Parallel Registers
Registers differ in how data is loaded into them and read out from them. The two primary modes of operation are serial and parallel.
8.1 Serial Registers
In a serial register, data bits are entered and retrieved one bit at a time, sequentially. This requires a single data input line and a single data output line.
- Serial-In, Serial-Out (SISO): Data is shifted into the register one bit at a time and shifted out one bit at a time. This is the simplest form and is often used in shift registers.
- Serial-In, Parallel-Out (SIPO): Data is shifted into the register serially, but all bits can be read out simultaneously in parallel.
Operation (SIPO Example)
Consider a 4-bit SIPO register using D flip-flops.
Data is shifted into the first flip-flop (D0) via a serial data input line, controlled by the clock pulse. When the clock pulse arrives, the bit at D0 is transferred to the output Q0. Simultaneously, the data previously stored in Q0 is shifted to Q1, Q1 to Q2, and so on.
To read the data, all outputs (Q0, Q1, Q2, Q3) can be accessed simultaneously. This means it takes 4 clock cycles to load 4 bits serially, but then all 4 bits are available in parallel.
8.2 Parallel Registers
In a parallel register, all data bits are loaded into and/or read from the register simultaneously. This requires multiple data input lines and multiple data output lines, one for each bit.
- Parallel-In, Serial-Out (PISO): Data bits are loaded into the register simultaneously, but they are retrieved one bit at a time serially.
- Parallel-In, Parallel-Out (PIPO): Data bits are loaded into the register simultaneously, and they can also be retrieved simultaneously. This is the fastest and most direct form of data transfer.
Operation (PIPO Example)
A 4-bit PIPO register uses four flip-flops. Each flip-flop has its own data input line (D0, D1, D2, D3) and its own data output line (Q0, Q1, Q2, Q3).
When a clock pulse is applied, all flip-flops capture their respective input data simultaneously. For example, if the inputs are 1011, after the clock pulse, the outputs will be Q0=1, Q1=0, Q2=1, Q3=1. All these bits are available at the outputs at the same time.
Parallel registers are used when fast data loading and retrieval are necessary, such as in CPU registers for arithmetic operations.
Shift Registers
Shift registers are a special type of serial register that can shift the stored data to the left or right with each clock pulse. They are fundamental for data manipulation, conversion between serial and parallel formats, and creating time delays.
Types of Shift Registers
- SISO (Serial-In, Serial-Out): Data enters serially and exits serially. Each clock pulse shifts data one position.
- SIPO (Serial-In, Parallel-Out): Data enters serially and can be read out in parallel. Useful for converting serial data streams into parallel data for processing.
- PISO (Parallel-In, Serial-Out): Data enters in parallel and is shifted out serially. Useful for converting parallel data to serial for transmission.
- PIPO (Parallel-In, Parallel-Out): Data enters and exits in parallel. Can also be designed to shift data serially.
- Universal Shift Register: A more complex register that can perform all types of serial and parallel data transfers (shift left, shift right, parallel load, serial load).
Shift registers are constructed using flip-flops (typically D or JK flip-flops) where the output of one flip-flop is connected to the input of the next, enabling the shifting action upon clock activation.