在复用器反馈无法在运行的Verilog(Feedback on Mux fail to run in

2019-10-22 05:56发布

我做了计算,其中的输出是下一个输入。 然而,复用器输出只提供X,并导致所有其他计算出问题。 如何解决这个问题? 它是由于时钟?

这里是我的代码:

module all2(input sel,clk,
           input signed [15:0]x,d,
           output signed [15:0]w,e,y);
localparam u = 16'd2;
wire [15:0]w1;
reg [15:0]y1,e1,u1,wk;
assign w = wk;
assign e = e1;
assign y = y1;
assign w1 = (sel)?wk:16'd0;
    always @(posedge clk or negedge clk)
    y1 <= x * w1;
    always @(posedge clk or negedge clk)
    e1 <= d - y1;
    always @(posedge clk or negedge clk)
    u1 <= e1 * x * u;
    always @(posedge clk or negedge clk)
    wk <= u1 + w1;    
endmodule

下面是测试平台:

module all2_tb();
reg sel, clk;
reg signed [15:0] x, d;
wire signed [15:0] w, e, y;

all2 U1(.sel(sel),.clk(clk),.x(x),.d(d),.w(w),.e(e),.y(y));

initial begin
    clk = 1'b0;
    forever
    #1 clk = ~clk;
end

initial begin
sel <= 1'b0;
x <= 16'd0;
d <= 16'd0;
#2;
sel <= 1'b1;
x <= 16'd1;
d <= 16'd2;
#1;
x <= 16'd3;
d <= 16'd4;
#1;
x <= 16'd5;
d <= 16'd6;
#1;
$stop;
end
endmodule

Answer 1:

输出去X不应导致计算的其余部分出问题,我会说这是周围的其他方式。 具有模块内部的X使输出去X.

在看看你的方程式您有:

w = wk;
e = e1;
y = y1;
w1 = (sel)?wk:16'd0;

always @(posedge clk or negedge clk) begin
  y1 <= x * w1;
  e1 <= d - y1;
  u1 <= e1 * x * u;
  wk <= u1 + w1;  
end

需要注意的是y1e1u1wk零时刻将是x ,因为你没有指定复位或初始条件。 我不知道你为什么被触发的时钟两边的触发器,但它通常有一个低电平有效复位引发了negedge。

always @(posedge clk or negedge rst_n) begin //<- negedge rst_n
  if (~rst_n) begin
    y1 <= 'd0;
    e1 <= 'd0;
    u1 <= 'd0;
    wk <= 'd0;
  end
  else begin
    y1 <= x * w1;
    e1 <= d - y1;
    u1 <= e1 * x * u;
    wk <= u1 + w1;  
  end 
end

一旦这被认为是我照顾再也看不到X的输出与您的模块。

在EDA游乐场



文章来源: Feedback on Mux fail to run in Verilog