Docsity

D Flip-Flop & Full Adder, Sintesi del corso di Sistemi di Controllo Lineare

Toggle sidebar
bg1
D Flip-Flop & Full Adder
Digital Logic Laboratory Report
Contents
1 D Flip-Flop 2
1.1 Definition ................................... 2
1.2 WorkingofDFlip-Flop............................ 2
1.3 TruthTable.................................. 2
1.4 VHDLCode.................................. 3
1.5 D Flip-Flop Timing Diagram . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 D Flip-Flop Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6.1 Data Storage Registers . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6.2 Data Transferring as Shift Registers . . . . . . . . . . . . . . . . . 4
2 Full Adder 5
2.1 Definition ................................... 5
2.2 Why Full Adder and Not Half Adder . . . . . . . . . . . . . . . . . . . . 5
2.3 FullAdderTruthTable............................ 5
2.4 BooleanExpressions ............................. 5
2.5 VHDLCode.................................. 6
2.6 Full Adder Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6.1 Ripple Carry Adder . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6.2 Arithmetic Logic Units (ALUs) . . . . . . . . . . . . . . . . . . . 7
1
pf3
pf4
pf5
pf8
pf9
pfa

Anteprima parziale del testo

Scarica D Flip-Flop & Full Adder e più Sintesi del corso in PDF di Sistemi di Controllo Lineare solo su Docsity!

D Flip-Flop & Full Adder

Digital Logic Laboratory Report

  • 1 D Flip-Flop Contents
    • 1.1 Definition
    • 1.2 Working of D Flip-Flop
    • 1.3 Truth Table
    • 1.4 VHDL Code
    • 1.5 D Flip-Flop Timing Diagram
    • 1.6 D Flip-Flop Applications
      • 1.6.1 Data Storage Registers
      • 1.6.2 Data Transferring as Shift Registers
  • 2 Full Adder
    • 2.1 Definition
    • 2.2 Why Full Adder and Not Half Adder
    • 2.3 Full Adder Truth Table
    • 2.4 Boolean Expressions
    • 2.5 VHDL Code
    • 2.6 Full Adder Applications
      • 2.6.1 Ripple Carry Adder
      • 2.6.2 Arithmetic Logic Units (ALUs)

1 D Flip-Flop

1.1 Definition

A flip-flop, also called a data flip-flop or delay flip-flop, is a basic electronic component used to store one bit of information. It has two stable states, called SET and RESET, which represent the binary values 1 and 0.

1.2 Working of D Flip-Flop

  • When the clock signal is low, the flip-flop keeps its current state and does not react to the D input.
  • On the rising edge of the clock signal, it reads the value on D and stores it. The value applied to D then appears at the Q output.
  • If D = 0, then Q becomes 0.
  • If D = 1, then Q becomes 1.

Figure 1: D Flip-Flop Circuit Diagram

1.3 Truth Table

Table 1: D Flip-Flop Truth Table

Clk (edge) D Q Q’ Q(n+1) Q’(n+1) ↓ 0 0 1 Q (no change) Q’ (no change) ↓ 1 0 1 Q (no change) Q’ (no change) ↑ 0 0 1 0 1 ↑ 1 1 0 1 0

Figure 4: D Flip-Flop Data Storage Register

1.6.2 Data Transferring as Shift Registers

Data enters via the Serial Data In line at D 3 and shifts one stage to the right with each rising clock edge. The first bit is latched into Q 3 , then propagates sequentially through Q 2 , Q 1 , and Q 0 over subsequent cycles. This operation, known as right-shift transmission, moves data from left to right (D 3 → D 0 ) across the register, effectively converting the one-bit-at-a-time input into a complete 4-bit value that can be read simultaneously from Q 3 – Q 0.

Figure 5: D Flip-Flop 4-bit Shift Register

2 Full Adder

2.1 Definition

A full adder is a combinational circuit that adds three binary inputs: A, B, and a carry input Cin. It produces two outputs: the sum (S) and the carry output (Cout). The sum is the result of the addition, and the carry output is sent to the next stage if there is an overflow.

Figure 6: Full Adder Block Diagram

2.2 Why Full Adder and Not Half Adder

We use a full adder because when a carry-in bit is available, a 1-bit half-adder cannot be used since it does not take a carry-in bit.

2.3 Full Adder Truth Table

Table 2: Full Adder Truth Table

A B Cin S Cout 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1

2.4 Boolean Expressions

S = A ⊕ B ⊕ Cin (1) Cout = A · B + Cin · (A ⊕ B) (2)

The governing equations are:

ci+1 = ai · bi + (ai ⊕ bi) · ci (3) si = ai ⊕ bi ⊕ ci (4)

Figure 9: N-bit Ripple Carry Adder

2.6.2 Arithmetic Logic Units (ALUs)

4.2.1 — Definition and Structural Composition of the ALU An Arithmetic Logic Unit (ALU) is a digital subsystem designed to perform arithmetic and logical op- erations on binary data. It is composed of multiple interconnected combinational circuits operating in parallel, with control logic selecting the desired operation and producing a final result along with status indicators.

Figure 10: ALU Block Diagram

4.2.2 — Fundamental Blocks of the ALU The ALU is constructed from the fol- lowing essential components:

a) Logic Gates (AND, OR, XOR) These implement bitwise logical operations:

• AND: F = A · B

• OR: F = A + B

• XOR: F = A ⊕ B

b) Arithmetic Unit (Adder/Subtractor) Built from cascaded full adders, this unit performs:

  • Binary addition
  • Binary subtraction (using two’s complement)

c) Multiplexer (MUX) Selects one of several computed outputs based on control signals.

d) Status Flags Provide information about the result:

  • Zero (Z)
  • Negative (N)
  • Carry (C)
  • Overflow (V)

e) Control Signals Define which operation the ALU performs.

4.2.3 — Role of the Full Adder in the ALU The full adder is the fundamental building block of the arithmetic unit. It enables the ALU to perform binary addition, which is the basis for most arithmetic operations.

Construction of a Multi-bit Adder A multi-bit adder is constructed by cascad- ing multiple full adders in series. For a 32-bit system:

  • 32 full adders are connected sequentially.
  • Each stage handles one bit position.

The carry propagates as:

ci+1 = ai · bi + (ai ⊕ bi) · ci (5)

This structure is known as a ripple-carry adder.

Implementation of Subtraction Subtraction is performed using the two’s com- plement method: A − B = A + (−B) = A + B + 1 (6) To implement this in hardware, each bit of B is XORed with a control signal SUB, and the initial carry-in is set to:

Cin = SUB (7)

17 -- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 18 architecture behavioral of adder_subtractor is 19 20 signal B_mod : std_logic_vector (N -1 downto 0) ; 21 signal carry : std_logic_vector ( N downto 0) ; 22 23 begin 24 -- Step 1: XOR each B bit with ctrl ( inverts B when ctrl =1) 25 B_mod <= B xor ( others = > ctrl ) ; 26 27 -- Step 2: ctrl is also the initial carry - in ( adds +1 for two ’ s complement ) 28 carry (0) <= ctrl ; 29 30 -- Step 3: Chain N full adders 31 gen : for i in 0 to N -1 generate 32 result ( i ) <= A ( i ) xor B_mod ( i ) xor carry ( i ) ; 33 carry ( i +1) <= ( A ( i ) and B_mod ( i ) ) or ( carry ( i ) and ( A ( i ) xor B_mod ( i ) ) ) ; 34 end generate ; 35 36 cout <= carry ( N ) ; 37 38 end architecture behavioral ;

Listing 1: 32-bit Parameterized Adder/Subtractor