Error Detection, Error Correction and Flip-Flops
These notes cover two important Computer Science topics: protecting data during transmission and storing binary state in sequential digital circuits.
You will learn parity checks, checksums, CRC, Hamming code, ARQ methods, and the operation of SR, JK, D, and T flip-flops.
1. Introduction to Error Detection and Correction
When data travels through a communication channel, electrical noise, interference, hardware faults, or transmission problems may change one or more bits. Error-control methods help a receiver detect whether data was damaged and, in some cases, correct the error.
Common Types of Errors
- Single-Bit Error: Only one bit changes from 0 to 1 or from 1 to 0.
- Multiple-Bit Error: More than one bit changes within a data unit.
- Burst Error: A group of bits within a data unit is affected. The bits between the first and last affected positions may or may not all be incorrect.
Error Detection vs Error Correction
| Error Detection | Error Correction |
|---|---|
| Determines whether received data may contain an error. | Identifies and corrects certain errors in received data. |
| May require retransmission if an error is detected. | Can recover from some errors without retransmission. |
| Examples: parity check, checksum, CRC. | Examples: Hamming code and other forward error-correction methods. |
2. Redundancy in Data Communication
Error-control techniques add extra information to the original data. This additional information is called redundancy. The receiver uses it to check whether the data changed during transmission.
More redundancy can improve error detection or correction capability, but it also increases the amount of data that must be transmitted.
3. Parity Check
Parity checking is a simple error-detection method. An extra bit, called a parity bit, is added to a data unit so the total number of 1s becomes either even or odd.
Even Parity
In even parity, the parity bit is chosen so that the total number of 1s is even.
Example: Data = 1011. The data contains three 1s, which is odd. For even parity, the parity bit must be 1, making the total number of 1s equal to four.
Odd Parity
In odd parity, the parity bit is chosen so that the total number of 1s is odd.
| Data | Number of 1s | Even Parity Bit | Odd Parity Bit |
|---|---|---|---|
| 1011 | 3 | 1 | 0 |
| 1010 | 2 | 0 | 1 |
4. Checksum
A checksum is an error-detection value calculated from a group of data units. The sender includes the checksum with the data, and the receiver recalculates it to check whether the data may have changed.
Checksums are commonly used by communication protocols and storage systems. They can detect many accidental errors, but no checksum method detects every possible kind of error.
General Checksum Process
- The sender divides data into fixed-size units.
- The sender calculates a checksum from those units.
- The checksum is transmitted with the data.
- The receiver recalculates the checksum from the received data.
- If the calculated value does not match the expected value, the receiver treats the data as damaged.
5. Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check, or CRC, is a widely used error-detection technique. It uses binary polynomial division to calculate a remainder that is sent with the data.
The sender and receiver use the same agreed generator value. If the received data does not produce the expected result during checking, an error is detected.
Why CRC Is Important
- CRC is effective at detecting many common transmission errors.
- It is especially good at detecting many burst-error patterns.
- It is used in technologies such as Ethernet, storage systems, and communication protocols.
- CRC detects errors but does not normally correct them by itself.
6. Hamming Code
Hamming code is an error-correction technique that adds parity bits to data bits. A standard Hamming code can identify and correct a single-bit error.
Parity-Bit Positions
In a Hamming code, parity bits are placed at positions that are powers of two: 1, 2, 4, 8, and so on.
If a message contains m data bits and requires r parity bits, the following condition is used for single-bit error correction:
2r ≥ m + r + 1
The receiver checks parity groups. The combined result identifies the location of a single-bit error, allowing the receiver to correct it.
SEC and SECDED
- SEC: Single Error Correction.
- SECDED: Single Error Correction, Double Error Detection. This commonly adds an overall parity bit to a Hamming code.
7. Retransmission and ARQ
Some systems detect an error and ask the sender to retransmit the affected data. This approach is called Automatic Repeat Request (ARQ).
- Stop-and-Wait ARQ: The sender transmits one frame and waits for an acknowledgement before sending the next frame.
- Go-Back-N ARQ: The sender may send multiple frames. When an error or loss occurs, the sender retransmits the affected frame and later unacknowledged frames.
- Selective Repeat ARQ: The receiver can accept correctly received frames and request retransmission of only missing or damaged frames.
Forward Error Correction
Forward Error Correction adds enough redundant information for a receiver to correct some errors without asking for retransmission. It is useful when retransmission is expensive or impractical, such as some wireless, satellite, or real-time communication systems.
8. Introduction to Flip-Flops
A flip-flop is a fundamental sequential logic circuit that stores one bit of binary information. Its two stable states represent logic 0 and logic 1.
Flip-flops are used in registers, counters, memory-related circuits, state machines, timing circuits, and digital control systems.
Characteristics of Flip-Flops
- Bistable Device: Has two stable states.
- Memory Element: Stores one bit of information.
- Sequential Circuit: Its output depends on present inputs and previous state.
- Clock-Controlled: Many flip-flops change state in response to a clock edge.
- Complementary Outputs: Q and Q' are normally complements of each other.
9. Latch vs Flip-Flop
| Aspect | Latch | Flip-Flop |
|---|---|---|
| Triggering | Usually level-sensitive. | Usually edge-triggered. |
| Control | Typically controlled by an enable signal. | Typically controlled by a clock signal. |
| Operation | Can change while the enable level is active. | Changes at the active clock edge. |
| Timing | Transparent while enabled. | Responds to a clock transition. |
| Applications | Simple temporary storage and timing circuits. | Registers, counters, and synchronous sequential circuits. |
10. Types of Flip-Flops
| Flip-Flop | Inputs | Main Function |
|---|---|---|
| SR | S, R | Set and reset operations. |
| JK | J, K | Set, reset, no change, and toggle operations. |
| D | D | Stores the value at the data input. |
| T | T | Toggles state when enabled. |
11. SR Flip-Flop
SR stands for Set-Reset. A conventional active-high SR flip-flop has two inputs: Set (S) and Reset (R).
| S | R | Qnext | Operation |
|---|---|---|---|
| 0 | 0 | Q | No change |
| 0 | 1 | 0 | Reset |
| 1 | 0 | 1 | Set |
| 1 | 1 | Invalid | Invalid condition |
Characteristic Equation: Qnext = S + R'Q
12. JK Flip-Flop
The JK flip-flop improves on the SR flip-flop by removing its invalid state. When J = K = 1, the output toggles.
| J | K | Qnext | Operation |
|---|---|---|---|
| 0 | 0 | Q | No change |
| 0 | 1 | 0 | Reset |
| 1 | 0 | 1 | Set |
| 1 | 1 | Q' | Toggle |
Characteristic Equation: Qnext = JQ' + K'Q
Race-Around Condition
In a level-triggered JK flip-flop, when J = K = 1 and the clock pulse remains active for too long, the output can toggle repeatedly during the same clock period. This is called the race-around condition.
Ways to Avoid Race-Around
- Use an edge-triggered JK flip-flop.
- Use a master-slave JK flip-flop.
- Use a suitably short clock pulse.
13. D Flip-Flop
D stands for Data or Delay. A D flip-flop transfers the value at D to Q at the active clock edge.
| D | Qnext | Operation |
|---|---|---|
| 0 | 0 | Store 0 |
| 1 | 1 | Store 1 |
Characteristic Equation: Qnext = D
Construction Using JK Flip-Flop
A D flip-flop can be created from a JK flip-flop by connecting: J = D and K = D'.
Applications
- Registers and temporary storage
- Pipeline registers
- Shift registers
- Signal synchronisation
- State storage in sequential circuits
14. T Flip-Flop
T stands for Toggle. A T flip-flop changes state when T = 1 and retains its previous state when T = 0.
| T | Qnext | Operation |
|---|---|---|
| 0 | Q | No change |
| 1 | Q' | Toggle |
Characteristic Equation: Qnext = T ⊕ Q
Equivalent form: Qnext = TQ' + T'Q
Construction Using JK Flip-Flop
A T flip-flop can be created from a JK flip-flop by connecting: J = K = T.
Applications
- Binary counters
- Frequency division
- Toggle circuits
- Sequential state transitions
15. Master-Slave Flip-Flop
A master-slave flip-flop uses two storage stages connected in cascade. The first stage is called the master, and the second is called the slave.
- The master receives input during one clock phase.
- The slave remains isolated during that phase.
- During the opposite clock phase, the master stops accepting new input.
- The slave receives the master's stored state.
- The output changes in a controlled manner.
Master-slave designs help reduce race-around problems in JK flip-flops.
16. Characteristic Equations
| Flip-Flop | Characteristic Equation |
|---|---|
| SR | Qnext = S + R'Q, for valid input combinations |
| JK | Qnext = JQ' + K'Q |
| D | Qnext = D |
| T | Qnext = T ⊕ Q |
17. Flip-Flop Excitation Tables
An excitation table shows the input values required to change a flip-flop from its present state Q to a desired next state Qnext. In these tables, X means “don't care.”
SR Flip-Flop Excitation Table
| Q | Qnext | S | R |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | X | 0 |
JK Flip-Flop Excitation Table
| Q | Qnext | J | K |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | X |
| 1 | 0 | X | 1 |
| 1 | 1 | X | 0 |
D and T Flip-Flop Excitation Table
| Q | Qnext | D Input | T Input |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
18. Comparison of Flip-Flops
| Feature | SR | JK | D | T |
|---|---|---|---|---|
| Inputs | S, R | J, K | D | T |
| Set | Yes | Yes | D = 1 | Through toggle |
| Reset | Yes | Yes | D = 0 | Through toggle |
| Toggle | No | J = K = 1 | No | T = 1 |
| Invalid State | Yes, in the conventional active-high form | No | No | No |
| Common Use | Basic storage concepts | Counters and control circuits | Registers and data storage | Counters and frequency division |
19. Quick Revision
- Parity checking detects odd numbers of bit errors but cannot correct errors.
- CRC is a powerful error-detection technique, especially for many burst errors.
- Hamming code can correct a single-bit error.
- ARQ uses acknowledgements, error detection, and retransmission.
- Flip-flops store one bit of information.
- SR means Set-Reset, JK can toggle, D stores data, and T toggles.
- For a JK flip-flop, J = K = 1 causes toggling.
- For a T flip-flop, T = 0 gives no change and T = 1 causes toggling.
- D flip-flops are widely used in registers and storage circuits.
- Race-around can occur in a level-triggered JK flip-flop when J = K = 1.
20. Practice Questions
- What is the difference between error detection and error correction?
- What is a parity bit?
- What is the limitation of parity checking?
- What is CRC and where is it used?
- What condition is used to calculate Hamming-code parity bits?
- What is the difference between ARQ and Forward Error Correction?
- What is a flip-flop?
- What is the difference between a latch and a flip-flop?
- Why is S = R = 1 invalid in a conventional active-high SR flip-flop?
- What is the race-around condition in a JK flip-flop?
- State the characteristic equation of a D flip-flop.
- State the characteristic equation of a T flip-flop.
- What is an excitation table?
- Why are D flip-flops commonly used in registers?