基础:最好对xilinx vivado 的仿真熟悉。对ip核使用熟悉。
1.创建一个工程
2.添加顶层文件rom.v
`timescale 1ns / 1ps
module rom(
input clk,
input rst_n,
output [15:0] data
);
reg [8:0] addr; //rom地址,每个地址对应一个数据,一共512个数据
always @(posedge clk or negedge rst_n)begin
if(rst_n==1'b0)begin
addr<=0;
end
else begin
addr<=addr+1; //地址+1
end
end
rom_ipcore your_instance_name (
.a(addr), // input wire [8 : 0] a 地址
.clk(clk), // input wire clk 时钟
.spo(data) // output wire [15 : 0] spo ,输出数据
);
endmodule
3.其中rom_ipcore.v这个文件是xilinx ROM IP核生成的。下面是ROM IP核的过程
(1)
(2)
(3)
(4)
(5)coe文件放入工程目录,如何生成coe文件,可以使用matlab,
参考博客:https://mp.csdn.net/postedit/103152762
(6)生成ip 核之后,我们可以点击下面的ip sources,可以看到ip核文件
4.测试文件
`timescale 1ns / 1ns
module rom_tb;
reg sclk;
reg rst_n;
wire [15:0] q_data;
initial begin
#50 sclk <= 1'b0;
#50 rst_n <= 1'b0;
#50 rst_n <= 1'b1;
end
always #10 sclk = ~sclk;
rom rom_uut(
.clk (sclk),
.rst_n (rst_n),
.data (q_data)
);
endmodule
5.仿真
6.设置一下数据格式
7.点击运行仿真,多点击几次,
8.结果