module ROM(clk, rst_n, q);
input clk;
input rst_n;
output [7:0] q;
wire [7:0]addr;
//控制地址变化
addr_ctrl addr_ctrl_dut(
.clk(clk),
.rst_n(rst_n),
.addr(addr)
);
//IP核:ROM
rom_8x256 my_rom_dut(
.address(addr),
.clock(clk),
.q(q)
);
endmodule
module addr_ctrl(clk, rst_n, addr);
input clk;
input rst_n;
output reg [7:0] addr; //控制ROM的地址变化(0~255)
always@ (posedge clk,negedge rst_n)begin
if(rst_n == 1'b0)
addr <= 8'd0;
else if(addr <= 8'd255)
addr <= addr + 8'd1;
else
addr <= 8'd0;
end
endmodule
`timescale 1ns/1ns
module tb_ROM();
reg clk;
reg rst_n;
wire [7:0] q;
initial
begin
clk = 1'b1;
rst_n <= 1'b0;
#10
rst_n <= 1'b1;
end
always #10 clk = ~clk;
ROM ROM_inst
(
.clk(clk),
.rst_n(rst_n),
.q(q)
);
endmodule
- 存在两个触发器,数据出现比地址出现晚了 2 个时钟周期
|