Lec8 Slides RTL
Lec8 Slides RTL
Lec8 Slides RTL
RTL coding
Introduction
4 bit
Binary
Counter
with
Parallel
Load
Counter with Parallel Load Ex2
//Binary counter with parallel load
module counter (Count,Load,IN,CLK,Clr,A,CO);
input Count,Load,CLK,Clr;
input [3:0] IN; //Data input
output CO; //Output carry
output [3:0] A; //Data output
reg [3:0] A;
assign CO = Count & ~Load & (A == 4'b1111);
always @(posedge CLK or negedge Clr)
if (~Clr) A = 4'b0000;
else if (Load) A = IN;
else if (Count) A = A + 1'b1;
else A = A; // no change, default condition
endmodule
Ripple Counter Example-1
4-bit
Binary
Ripple
Counter
Ripple Counter Example-2
//Ripple counter
module ripplecounter(A0,A1,A2,A3,Count,Reset);
output A0,A1,A2,A3;
input Count,Reset;
//Instantiate complementing flip-flop
CF F0 (A0,Count,Reset);
CF F1 (A1,A0,Reset); //Complementing flip-flop
CF F2 (A2,A1,Reset); //Input to D flip-flop = Q'
CF F3 (A3,A2,Reset); module CF (Q,CLK,Reset);
endmodule output Q;
input CLK,Reset;
reg Q;
always@(negedge CLK or posedge Reset)
if(Reset) Q=1'b0;
else Q=#2 (~Q);
endmodule
Ripple Counter Example-3
//Stimulus for testing ripple counter
module testcounter;
reg Count;
reg Reset;
wire A0,A1,A2,A3;
//Instantiate ripple counter
ripplecounter RC (A0,A1,A2,A3,Count,Reset);
always
#5 Count = ~Count;
initial
begin
Count = 1'b0;
Reset = 1'b1;
#4 Reset = 1'b0;
#165 $finish;
end
endmodule
Summary
Shift registers and RTL coding
Behavioural and Structual Description for
Sequential Circuits