首页 > 解决方案 > PISO 寄存器输出不如预期

问题描述

我在 PISO verilog 寄存器中有问题。下面是我的代码

`timescale 1ns / 1ps
module PISO(
    input clk,
    input load, 
    input [3:0] d,
    output reg Qout);  

reg [3 : 0]Q;  


always @ (posedge clk)
begin

if ( load  ) 
  Q <= d;
else
begin 
  Qout <= d[3];
  Q<= { Q[2:0] , 1'b0 };
  end
end
endmodule

和我的测试台

`timescale 1ns / 1ps
module PISO_tb();

PISO uut(clk,load,d,Qout);
reg clk;
reg load;
reg [3:0]d;
wire Qout;

initial begin
clk=0;
forever #5 clk = ~clk;
end

initial begin

load = 1;
d[0] = 1'b0;
d[1] = 1'b1;
d[2] = 1'b0;
d[3] = 1'b1;
#6 load = 0;

end
endmodule

它不能正常工作,请帮我测试一下吧?因为我认为verilog代码没问题,应该可以正常工作。

标签: embeddedverilogfpga

解决方案


您希望Qout信号成为移位寄存器 ( Q) 的输出而不是输入,以便输出切换而不是保持为 1。更改:

Qout <= d[3];

至:

Qout <= Q[3];

推荐阅读