0

I'm trying to design a 64-bit Shift register in Verilog HDL but when I test the code with a testbench, all the bits are zeros. I don't know where I'm going wrong. Here is my code and the test bench result:

module ShiftRegister (shift_out, clk, shift_in, rst); //module ports
 parameter n = 64; //Parameter n declared to store 64
 input rst;
 input [n-1:0] shift_in; //64-bit input shift_in
 input clk; //Input clock
 output [n-1:0] shift_out; //64-bit output shift_out
 reg [n-1:0] ff; //64-bit flipflop
  assign shift_out = ff [n-1:0]; //give the output of the 64th bit
  //The operation of verilog: 
   always @ (posedge clk or posedge rst) //Always at the rising edge of the clock
   begin
     if (rst) begin
     ff <= 0;
   end else begin
     ff <= ff << 1;  //Shift bits to the left by 1
     ff[0] <= shift_in; //Take the input bits and give it to the first flipflop
   end
   end
 endmodule


 module ShiftRegister_tb; //Module shiftRegister_tb
  parameter n = 64; //Parameter n declared to store 64
  reg [n-1:0] shift_in; //64-bit register input shift_in
  reg clk, rst; //register clock
  wire [n-1:0] shift_out; //64-bit wire output shift_out
  ShiftRegister DUT(shift_out, clk, shift_in,rst); //Calling the module
   initial
   begin
     clk = 0; //clock = 0 initally
     rst = 1;
     shift_in = 64'd34645767785344; //Random decimal number to test the code 
     #100;
     rst = 0;
     #50_000 $finish;
   end   
  always #50 clk =~clk; //invert the clock input after 50ps
 endmodule //ShiftRegister testbench 

Testbench Result

1 Answer 1

1

Here ff[0] <= shift_in;, you are trying to assign a 64-bit variable to 1-bit variable. Since you use a even number (64'd34645767785344) for shift_in in your testbench, its LSB is 0. Therefore, you keep inserting 0 to ff.

Make your shift_in input 1-bit and change your testbench such that you will give 1-bit at a time as input.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply. So what I can also do is send input bits like one at a time? i've tried doing it this way but it doesn't work as expected. Is there a way I can just insert 64-bits? like i'm looking to input random binary like 10101011110111 etc.
Yes. Then you need to define a way to "initialize" your register. For example, define an input port named load. Then you can initialize your register with making load 1 and giving your 64-bit input. When load is 0, your circuit should shift ff.
When I send a 1-bit input '1', then it shifts. But i'm not able to send another bit after that like it doesn't input the, shift_in = 1 #10 shift_in = 0 #10 shift_in = 1 , It only takes in the first '1' and not the other bits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.