Lab9
Lab9
LAB-9
Submitted By :
Name : Balla P V S S Ramanjaneya Kumar
Roll No : 220102012
Section : C(ECE)
EC3152
Experiment Name :
SR & D FLIPFLOP
Submitted on:
25th October 2024
Submitted to:
Professor Ngasepam Monica Devi
Aim:
To design, implement, and simulate the Verilog code for SR and D flipflops. The objective is
to understand the behavior and functionality of both flip-flops, including their response to
inputs and their use in storing binary information based on clock signals.
Software/Tools required:
Xilinx Vivado 2024.1
Theory:
Flip-flops are fundamental sequential circuits in digital electronics, used to store binary data.
They are edge-triggered devices, meaning they capture and hold input data only on specific
clock edges. Among the various types of flip-flops, the SR (Set-Reset) and D (Data) flip-flops
are two of the most commonly used. Each has unique characteristics, making them suitable
for specific applications in digital systems.
i. SR Flip Flop
The SR (Set-Reset) flip-flop is a basic flip-flop type with two primary inputs: S (Set) and R
(Reset). The SR flip-flop has two stable states (1 and 0) and is used to store a single bit of
data based on the conditions of the S and R inputs.
Operations:
• When the S (Set) input is high and R is low, the output Q is set to 1.
• When the R (Reset) input is high and S is low, the output Q is reset to 0.
• When both S and R are low, the output Q retains its previous state (memory).
• When both S and R are high, the output state is undefined or invalid, as it causes
both Q and its complement Q‾\overline{Q}Q to be 0, which conflicts with the
flip-flop’s logical definition.
Logic Diagram:
Truth Table:
S R Q (Next State) Qb
0 0 Q (Hold) Qb
0 1 0 1
1 0 1 0
1 1 Invalid Invalid
ii. D Flip Flop
The D (Data or Delay) flip-flop is a simpler and more widely used flip-flop that has a single
data input (D) and a clock input. It is designed to store the value at the D input only on the
rising or falling edge of the clock signal, depending on its configuration.
Operation:
• The D flip-flop captures the value at the D input and transfers it to the output
Q on the specified clock edge.
• If D = 1 at the clock edge, the output Q is set to 1.
• If D = 0 at the clock edge, the output Q is reset to 0.
• The D flip-flop avoids the indeterminate state issue seen in SR flipflops by
having only one input signal.
Logic Diagram:
Truth Table:
D CLK Q (Next State) Qb
0 Rising 0 (Reset) 1
1 Rising 1 (Set) 0
Procedure:
1. Create a Project:
o Start by creating a new project in the Verilog design tool. Assign a suitable
name for the project based on the experiment being conducted.
4. View Schematic:
o To view the RTL schematic, navigate to "Open Elaborated Design"
under the RTL Analysis section. This helps visualize the logic gates and
connections implemented in the design.
6. Match Inputs/Outputs:
o The testbench should have the same number of inputs and outputs as
the design file. These variables will be passed into the design module during
simulation.
8. Run Synthesis:
o Once both the design and testbench files are ready, run "Synthesis"
under the Synthesis tab. This step ensures the design is logically correct.
9. Run Simulation:
o After synthesis, proceed to the Simulation tab and run the simulation
to verify the functionality of the design.
Verilog Code:
i. SR Flip Flop
module sr_flip_flop(S,R,CLK,Q,Qb);
input S,R,CLK;
output Q,Qb;
assign Q = ~((R&CLK)|Qb);
assign Qb = ~((S&CLK)|Q);
endmodule ii. D Flip Flop
module d_flip_flop(D,Db,CLK,Q,Qb);
input D,Db,CLK; output Q,Qb;
sr_flip_flop SR1(D,Db,CLK,Q,Qb);
endmodule
Verilog Testbench:
i. SR Flip Flop
module tb_srflipflop();
reg S,R,CLK; wire
Q,Qb; sr_flip_flop
dut(.S(S),.R(R),.CLK(CL
K),.Q(Q),.Qb(Qb));
initial begin
CLK = 0; forever #5 CLK = ~CLK;
end initial begin S = 0;
R = 0;
#10 S = 0; R = 1;
#10 S = 1; R = 0;
#10 S = 1; R = 1;
#10 $finish;
end endmodule
Output Schematic:
i. SR Flip Flop
ii. D Flip Flop
Output Waveform:
i. SR Flip Flop