Professional Documents
Culture Documents
Day 9 GC
Day 9 GC
Controls
COURSE: anddesign
VLSI Verilogusing
Control blocks
Verilog
Latch Vs Flip Flop
CHAPTER: - Five
PPT SL.NO.: - 01
Latch is level triggered i.e. the output of Flip Flop are edge-triggered i.e. the output
the present sate and input of the next state and the next sate changes when there is a
depends on the level i.e. binary input 1 or change in clock pulse whether it may be
0. +ive or –ive clock pulse.
Flip-Flops
Flip Flops to be considered are:
SR Flip Flop
JK Flip Flop
D Flip Flop
T Flip Flop
SR Flip Flop:
◻ SR Flip Flop: Basic Flip Flop. Similar to S-R
latch except clk signal and two AND gates. The
circuit responds to the positive edge of clock
pulse to the inputs of S & R.
Flip-Flops
Truth Table of SR Flip Flop
Clock S R Q n+1 State
0 x x Qn
1 0 0 Qn Hold
1 0 1 0 Reset
1 1 0 1 Set
1 1 1 x Invalid
module srff_dataflow(q,qbar,s,r,clk);
input s,r,clk;
output q, qbar;
assign q = clk? (s | ((~r) & q)) : q;
assign qbar = ~q;
endmodule
SR Flip Flop (data flow)
Flip flops are edge-triggered circuits. When we
use a conditional operator, the statement is not
executed at the clock edges(HIGH to LOW or
LOW to HIGH) but the clock level(HIGH and
LOW). Hence, the dataflow model of SR flip flop
will work only as a latch. And not as an authentic
flip-flop that triggers on clock edges.
SR Flip-Flop using behavioral modeling
module SR_flipflop(q,q1,r,s,clk);
output q,q1;
input r,s,clk;
reg q,q1;
initial
//Initial Block is used to set the values of q and q1 initially because then these values will be used
as feedback in the always block. Initial Block is executed only once in the code.
begin
q=1'b0; q1=1'b1; // q is set to 0 and q1 is set to 1.
end
always @(posedge clk)
begin
case({s,r})
{1'b0,1'b0}: begin q=q; q1=~q; end
{1'b0,1'b1}: begin q=1'b0; q1=1'b1; end
{1'b1,1'b0}: begin q=1'b1; q1=1'b0; end
{1'b1,1'b1}: begin q=1'bx; q1=1'bx; end
endcase
end
endmodule
SR Flip-Flop Test Bench
module dff_test;
reg S,R, CLK;
wire Q, QBAR;
initial begin
$monitor("simtime = %g, CLK = %b, S = %b, R = %b, Q = %b, QBAR = %b", $time, CLK, S, R, Q,
QBAR);
clk=0;
forever #10 clk = ~clk;
end
initial begin
S= 1; R= 0;
#100; S= 0; R= 1;
#100; S= 0; R= 0;
#100; S= 1; R=1;
end
endmodule
Thank you!
NIELIT www.nielit.gov.in/haridwar