Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is my verilog code and the testbench code however there is an issue with my waveform not being accurate can you please find the

Here is my verilog code and the testbench code however there is an issue with my waveform not being accurate can you please find the issue and explain why?
module line (
input wire rst_n,// Active low reset
input wire clk,// Clock
input wire signed [3:0] m,// Signed input
input wire signed [3:0] x,// Signed input
input wire signed [3:0] c,// Signed input
input wire valid_in,// Inputs valid
output reg signed [8:0] y,// Signed output
output reg y_valid // Y valid, driven by design
);
reg signed [8:0] product_reg; // Pipeline register for product
reg signed [8:0] sum_reg; // Pipeline register for sum
// Stage 1: Multiplier pipeline stage
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
product_reg =9'b0; // Reset8 product register
else if (valid_in)
product_reg = m * x; // Calculate product
end
// Stage 2: Adder pipeline stage
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
sum_reg =9'b0; // Reset sum register
else if (valid_in)
sum_reg = product_reg + c; // Calculate sum
end
// Output and valid signal assignment
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
y =9'b0; // Reset output
y_valid =1'b0; // Reset valid signal
end
else if (valid_in) begin
y = sum_reg; // Assign output
y_valid =1'b1; // Set valid signal
endmodule 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
endmodule
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions