在这次小测试中使用的是Xilinx的ise软件
1、调用rom,并且将*.coe文件初始化进rom里
2、编写顶层模块rom_top.v 将rom例化进rom_top.v里面
module rom_top(
input wire clk,
input wire rst_n,
input wire [3:0] rd_addr,
output wire [7:0] rd_data
);
sp_rom_16x8 sp_rom_16x8 (
.clka(clk), // input clka
.rsta(rst_n), // input rsta
.addra(rd_addr), // input [3 : 0] addra
.douta(rd_data) // output [7 : 0] douta
);
endmodule
3、编写测试文件tb_rom.v,将top_rom.v例化进去,并且模拟时钟clk、复位rst_n、读地址rd_addr、(注意:rom的复位是高复位)
`timescale 1ns/1ns
module tb_rom;
reg clk;
reg rst_n;
reg [3:0] rd_addr;
wire [7:0] rd_data;
initial begin
clk = 0;
rst_n <= 1;
rd_addr <= 0;
#100
rst_n <= 0;
end
always #10 clk = ~clk;
always@(posedge clk or negedge rst_n)
if(rst_n == 1)
rd_addr <= 0;
else
rd_addr <= rd_addr + 1'b1;
rom_top rom_top_inst(
.clk (clk ),
.rst_n (rst_n ),
.rd_addr (rd_addr ),
.rd_data (rd_data )
);
endmodule
4、仿真
附*.coe文件
memory_initialization_radix=16;
memory_initialization_vector=
00,
11,
22,
33,
44,
55,
66,
77,
88,
99,
aa,
bb,
cc,
dd,
ee,
ff;