Forum Discussion
Altera_Forum
Honored Contributor
10 years ago --- Quote Start --- And how is the mem defined? What is the memory code? Why do you delay the read address on a read task? --- Quote End --- Memory is defined as logic [7:0] memory [0:31] Please find the entire code below. The memory module and test bench are instantiated in the top module.
****************** TOP MODULE ******************
module top;// SYSTEMVERILOG: timeunit and timeprecision specification
timeunit 1ns;
timeprecision 1ns;
// SYSTEMVERILOG: logic and bit data types
bit clk;
wire read;
wire write;
wire addr;
wire data_out; // data_from_mem
wire data_in; // data_to_mem
// SYSTEMVERILOG:: implicit .* port connections
mem_test test (.*);
// SYSTEMVERILOG:: implicit .name port connections
mem memory ( .clk, .read, .write, .addr,
.data_in, .data_out
);
always# 5 clk = ~clk;
endmodule
*********************** MEMORY MODULE ***********************
module mem ( input clk,
input read,
input write,
input logic addr ,
input logic data_in ,
output logic data_out
);
// SYSTEMVERILOG: timeunit and timeprecision specification
timeunit 1ns;
timeprecision 1ns;
// SYSTEMVERILOG: logic data type
logic memory ;
always @(posedge clk)
if (write && !read)
// SYSTEMVERILOG: time literals
memory <= data_in;
// SYSTEMVERILOG: always_ff and iff event control
always_ff @(posedge clk iff ((read == '1)&&(write == '0)) )
data_out <= memory;
endmodule Below is the output. I am writing "zero" in all the addresses and reading. You willbe seeing "x" once i start the reading process. That's the issue i am trying to fix.
**************************** OUTPUT ******************************
addr=00000, data_in=00000000
addr=00001, data_in=00000000
addr=00010, data_in=00000000
addr=00011, data_in=00000000
addr=00100, data_in=00000000
addr=00101, data_in=00000000
addr=00110, data_in=00000000
addr=00111, data_in=00000000
addr=01000, data_in=00000000
addr=01001, data_in=00000000
addr=01010, data_in=00000000
addr=01011, data_in=00000000
addr=01100, data_in=00000000
addr=01101, data_in=00000000
addr=01110, data_in=00000000
addr=01111, data_in=00000000
addr=10000, data_in=00000000
addr=10001, data_in=00000000
addr=10010, data_in=00000000
addr=10011, data_in=00000000
addr=10100, data_in=00000000
addr=10101, data_in=00000000
addr=10110, data_in=00000000
addr=10111, data_in=00000000
addr=11000, data_in=00000000
addr=11001, data_in=00000000
addr=11010, data_in=00000000
addr=11011, data_in=00000000
addr=11100, data_in=00000000
addr=11101, data_in=00000000
addr=11110, data_in=00000000
addr=11111, data_in=00000000
addr=00000, data_out=xxxxxxxx
addr=00001, data_out=00000000
addr=00010, data_out=00000000