Professional Documents
Culture Documents
2
Basic Operation of Universal Shift Register
3
Serial and Parallel Loading
4
Verilog Code for Universal Shift Register
Here is an example of Verilog code for a universal
shift register:
module usr(dataout,clock,reset,mode,datain);
output reg[3:0]dataout;
input clock,reset;
input [1:0]mode;
input [3:0]datain;
always@(posedge clock)
begin
if(reset)
dataout<=0;
else
begin
case(mode)
2'b00:dataout<=dataout;
2'b01:dataout<={datain[0],datain[3:1]};
2'b10:dataout<={datain[2:0],datain[3]};
2'b11:dataout<=datain;
endcase
end
end
endmodule
5
Verilog Code for Universal Shift Register
Here is an testbench code for a universal shift register:
module usr_testbench();
reg [3:0]datain;
reg clock,reset;
reg [1:0]mode;
wire [3:0]dataout;
usr m1(dataout,clock,reset,mode,datain);
initial begin
clock=0;
repeat(100)
#20 clock=~clock;
end
initial begin
datain=4'b1010; mode=2'b00;reset=1’b0;
#20;
datain=4'b1010;mode=2'b01;reset=1'b0;
#20;
datain=4'b1010;mode=2'b10;reset=1'b0;
#20;
datain=4'b1010;mode=2'b11;reset=1'b0;
#20;
$finish();
end
endmodule
6
Applications of Universal Shift Register
7
Summary and Conclusion
8
CN- Flipflop (Change -No Change Flip
Flop) using DFF and 2:1 Mux
Introduction to CN-FLIPFLOP
In C-N (Change – No change) flip-flop, there
won’t be any change in output as long as N is 0,
irrespective of C.
10
Verilog Code for CN-FLIPFLOP
Here is an example of Verilog code for a cn-flipflop:
module mux21(a,b,s,y);
input a,b,s;
output reg y;
always @(a or b or s)
begin
case(s)
0:y=a;
1:y=b;
default:y=1'b0;
endcase
end
endmodule
11
Verilog Code for CN-FLIPFLOP
Here is an example of Verilog code for a cn-flipflop:
*D flipflop code:
module dff(d,clk,reset,q);
input d,clk,reset;
output reg q;
always@(posedge clk)
begin
if(reset)
q=0;
else
q=d;
end
endmodule
12
Verilog Code for CN-FLIPFLOP
module cn_flipflop(c,n,clk,q,qbar);
input c,n,clk;
output q,qbar;
wire cn,n_bar,d_wire;
mux21 mux1(1'b0,c,n,cn);
mux21 mux2(1'b1,1'b0,n,n_bar);
mux21 mux13(cn,n_bar,q,d_wire);
dff dff1(.d(d_wire),.clk(clk),.reset(),.q(q));
assign qbar=~q;
endmodule
13
Verilog Code for CN-FLIPFLOP
Here is an testbench code for a CN-flipflop:
module cn_flipflop_testbench();
reg c,n,clk;
wire q,qbar;
cn_flipflop m1(c,n,clk,q,qbar);
initial begin
clk=0;
repeat(100)
#20 clk=~clk;
end
initial begin
c=0;n=0;#20;
c=0;n=1;#20;
c=1;n=0;#20;
c=1;n=1;#20;
end
endmodule
14
INTRODUCTION TO A FREQUENCY
DIVIDER BY USING AN ODD
NUMBER
FREQUENCY DIVIDER BY ODD NUMBER
• Frequency or clock dividers are among the most common circuits
used in digital systems.
• Somehow dividing the frequency with an odd number is not that
easy.
• Designing an frequency divider by even number is easy
• A simple odd number frequency divider with 50% duty cycle is
presented. The odd number frequency divider consists of a general odd
number counter and the proposed duty cycle trimming circuit. The duty
cycle trimming circuit can output 50% duty cycle with only additional
six transistors.
circuit diagram of frequency divider
Verilog code
module clk_div3(clk,reset, clk_out);
input clk;
input reset;
output clk_out;
clk_div3 t1(clk,reset,clk_out);
initial
clk= 1'b0;
always
#5 clk=~clk;
initial
begin
#5 reset=1'b1;
#10 reset=1'b0;
#100 $finish;
end
initial
$monitor("clk=%b,reset=%b,clk_out=%b",clk,reset,clk_out);
initial
begin
$dumpfile("clkdiv3_tb.vcd");
$dumpvars(0,clkdiv3_tb);
end
endmodule
Thoughts! Questions!
Feedback!
Let’s hear them…