4-Bit Shift Register in Verilog

  • Thread starter pags920
  • Start date
  • Tags
    Shift
In summary, the conversation is about a person struggling to load a number into a 4-bit shift register using Verilog. They have tried various methods to find the error, but have been unsuccessful. They share their code and ask for help in identifying the typo causing the issue. The conversation also includes a tutorial on designing a 4-bit register in Verilog, which may be helpful in finding the error.
  • #1
pags920
21
0
This is basically a continuation of a previous problem I submitted. I worked out the previous problem, now I need to figure out another problem. This 4-bit shift register won't load the number I am trying to load. I have exhausted every possible error where it could be wrong. I commented lines out to see if I could pinpoint it, but I cannot seem to find out why it won't load my number. This was done using Verilog.

If anyone can figure out where the typo is so I can load the register with a value, that would be most helpful.

Code:
module t_Shift_Register_4_str;
wire [3:0] a_par;
reg [3:0] i_par;
reg s1,s0,msb_in,lsb_in,clk,clear,select;
Shift_Register_4_str m0(a_par,i_par,s1,s0,msb_in,lsb_in,clk,clear,select);
initial #100 $finish;
initial begin clk=0; forever #10 clk=~clk; end
initial fork
#0 i_par=4'b0100; clear=1; select=1;
#0 s1=1'b1; #20 s1=1'b1; #40 s1=1'b0; #60 s1=1'b0;
#0 s0=1'b1; #20 s0=1'b0; #40 s1=1'b0; #60 s0=1'b1;
#0 msb_in=1'b1;
#0 lsb_in=1'b1;
join
endmodule

module Shift_Register_4_str (A_par,I_par,Select,s1,s0,MSB_in,LSB_in,CLK,Clear);
output [3:0] A_par;
input [3:0] I_par;
input [1:0] Select;
input s1,s0,MSB_in,LSB_in,CLK,Clear;
assign {Select[1],Select[0]} = {s1,s0};
stage ST0 (A_par[0],A_par[1],LSB_in,I_par[0],A_par[0],Select,CLK,Clear);
stage ST1 (A_par[1],A_par[2],A_par[0],I_par[1],A_par[1],Select,CLK,Clear);
stage ST2 (A_par[2],A_par[3],A_par[1],I_par[2],A_par[2],Select,CLK,Clear);
stage ST3 (A_par[3],MSB_in,A_par[2],I_par[3],A_par[3],Select,CLK,Clear);
endmodule

module stage (i0,i1,i2,i3,Q,select,CLK,Clr);
input i0,i1,i2,i3;
output Q;
input [1:0] select;
input CLK,Clr;
wire mux_out;
Mux_4_x_1 M0 (mux_out,i0,i1,i2,i3,select);
D_flip_flop M1 (Q,mux_out,CLK,Clr);
endmodule

module Mux_4_x_1 (mux_out,i0,i1,i2,i3,select);
output mux_out;
input i0,i1,i2,i3;
input [1:0] select;
reg mux_out;
always @ (select or i0 or i1 or i2 or i3)
case ({select})
2'b00: mux_out = i0;
2'b01: mux_out = i1;
2'b10: mux_out = i2;
2'b11: mux_out = i3;
endcase
endmodule

module D_flip_flop (Q,D,CLK,Clr);
output Q;
input D,CLK,Clr;
reg Q;

always @ (posedge CLK or negedge Clr)
if(~Clr) Q<=1'b0; else Q<=D;
endmodule
 
Physics news on Phys.org
  • #2
There’s a tutorial on designing a 4 bit register in Verilog. Check it out and you might spot your error.

 

1. What is a 4-bit shift register in Verilog?

A 4-bit shift register in Verilog is a digital circuit that can store and manipulate 4 bits of data. It is commonly used in digital systems for tasks such as data storage, data transfer, and data manipulation.

2. How does a 4-bit shift register work in Verilog?

A 4-bit shift register in Verilog works by sequentially storing and shifting bits of data through a series of flip-flops. The shift operation can be either left or right, and the data can be shifted in or out of the register depending on the design.

3. What are the advantages of using a 4-bit shift register in Verilog?

One advantage of using a 4-bit shift register in Verilog is its versatility. It can be used for different purposes such as parallel-to-serial conversion, serial-to-parallel conversion, and data manipulation. Additionally, it requires fewer logic gates compared to other types of registers, making it more efficient in terms of hardware usage.

4. What are the limitations of a 4-bit shift register in Verilog?

One limitation of a 4-bit shift register in Verilog is its limited storage capacity. It can only store 4 bits of data at a time, which may not be sufficient for certain applications. Additionally, it can only handle a single data stream at a time, which may not be suitable for parallel processing.

5. Can a 4-bit shift register be expanded to store more bits in Verilog?

Yes, a 4-bit shift register in Verilog can be expanded to store more bits by cascading multiple registers together. This allows for an increase in storage capacity and enables the handling of multiple data streams simultaneously. However, this will also require more hardware resources and may affect the overall performance of the circuit.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
9
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
987
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
12K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
19K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
9K
Back
Top