Verilog:使用触发器实现管道硬件

时间:2017-11-03 21:57:45

标签: verilog hardware system-verilog flip-flop

如何在Verilog中创建简单的一阶段管道?

enter image description here

2 个答案:

答案 0 :(得分:0)

创建单个状态管道的最简单方法是创建两个始终与管道输入(in_pipe)同步的块,如下所示。这项工作是因为事件如何在模拟器时间周期中排队。

module pipeline (reset,in,clock,out)

input reset, input, clock;
output out;`

logic reset, input, clock;
reg out, in_pipe;

always @(posedge clock or negedge reset)
 begin
  if(reset)
   begin
   in_pipe <= 0;
   end
 else
   begin
   in_pipe <= in;
   end
 end

always @(posedge clock or negedge reset)
begin
 if(reset)
  begin
  out<= 0;
  end
 else
  begin
  out<= in_pipe;
  end
end

答案 1 :(得分:0)

module pipeline#(
   parameter PIPE_NUM = 2,
   parameter DATA_WIDTH = 32 
)(
  input clock,
  input [DATA_WIDTH-1:0]data_in,
  output [DATA_WIDTH-1:0]data_out
);

 //synthesis translate_off
 initial begin
   if(PIPE_NUM < 1) begin
       $fatal("Error: PIPE_NUM must be greater than 0!");
   end 
 end 
 //synthesis translate_on

 reg [DATA_WIDTH-1:0]pipeline_reg[PIPE_NUM-1:0]/*synthesis preserve*/;

 assign data_out = pipeline_reg[PIPE_NUM-1];

 integer p;
 always @(posedge clock)begin
    pipeline_reg[0] <= data_in; 
    for(p = 1;p < PIPE_NUM;p = p+1)begin
       pipeline_reg[p] <= pipeline_reg[p-1];
    end
 end 

endmodule