Question: Why does my testbench waveform have a delay and the values are off? Here is the design file: module line ( input rst _ n

Why does my testbench waveform have a delay and the values are off?
Here is the design file:
module line (
input rst_n,// Active low reset
input clk,// Clock
input signed [3:0] m,// Signed input m
input signed [3:0] x,// Signed input x
input signed [3:0] c,// Signed input c
input valid_in,// Inputs valid
output reg signed [8:0] y,// Signed output y
output reg y_valid // Y valid, driven by design
);
reg signed [8:0] product; // Intermediate result for mx
// Stage 1: Calculate the product (mx)
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
product =9'b0;
end else if (valid_in) begin
product = m * x;
end
end
// Stage 2: Calculate the sum (product + c)
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
y =9'b0;
y_valid =1'b0;
end else if (valid_in) begin
y = product + c;
y_valid =1'b1;
end
end
endmodule
Here is the testbench file which was provided by the professor (should not be modified):
module tb_line(
);
reg clk;
reg rst_n;
wire signed [3:0] m;
wire signed [3:0] x;
wire signed [3:0] c;
wire signed [8:0] y;
wire signed [8:0] tb_y;
reg valid_in;
wire y_valid;
reg [3:0] addr_in, addr_y;
line dut (.*);
rom #(.addr_width (4),.data_width (4),.init_file("m.dat"))
m_mem(
.addr(addr_in),
.data (m)
);
rom #(.addr_width (4),.data_width (4),.init_file("x.dat"))
x_mem(
.addr(addr_in),
.data (x)
);
rom #(.addr_width (4),.data_width (4),.init_file("c.dat"))
c_mem(
.addr(addr_in),
.data (c)
);
rom #(.addr_width (4),.data_width (9),.init_file("y.dat"))
y_mem(
.addr(addr_y),
.data (tb_y)
);
always #5 clk = ~clk;
//integer file_handle;
initial
begin
//file_handle = $fopen("output.txt","w");
clk =0;
rst_n =1'h0;
valid_in =0;
#73 rst_n =1'h1;
#17;
addr_in =4'h0;
#20;
valid_in =1;
for (integer i =0; i 16; i = i +1)
begin
#10;
//assert (y == tb_y);
addr_in = addr_in +1;
end
valid_in =0;
//#50;
//$fclose(file_handle);
end
always_ff @ (posedge clk)
begin
if (!rst_n)
begin
addr_y = #0.14'h0;
end
else if (y_valid)
begin
//$fwrite(file_handle, "%b
", y);
assert (y == tb_y)
else $fatal("y not equal to tb_y");
addr_y = #0.1 addr_y +1;
end
end
 Why does my testbench waveform have a delay and the values

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!