本文内容:基于 Cyclone IV在 Quartus 中配置 IP 核中的 PLL 、 RAM 与 FIFO 的详细步骤
`timescale 1ns/1ns
module tb_pll;
// Parameter definition
parameter CYC_CLK = 20 ;
// Drive signal
reg tb_clk ;
reg tb_rst_n ;
// Observation signal
wire c0 ;
wire c1 ;
wire c2 ;
wire c3 ;
wire locked ;
// Module calls
PLL_demo PLL_demo_inst (
/*input */ .inclk0 (tb_clk ),
/*input */ .areset (~tb_rst_n ),
/*output*/ .c0 (c0 ),
/*output*/ .c1 (c1 ),
/*output*/ .c2 (c2 ),
/*output*/ .c3 (c3 ),
/*output*/ .locked (locked )
);
// System initialization
initial tb_clk = 1'b1;
always #10 tb_clk = ~tb_clk;
initial begin
tb_rst_n = 1'b0;
#20;
tb_rst_n = 1'b1;
#(500 * CYC_CLK);
$stop;
end
endmodule
`timescale 1ns/1ns
module tb_ram;
// Parameter definition
parameter CYC_CLK = 20 ;
// Drive signal
reg tb_clk ;
reg tb_rst_n ;
reg [ 7:0] address ;
reg [ 7:0] data ;
reg rden ;
reg wren ;
// Observation signal
wire [ 7:0] q_out ;
// Module calls
RAM_demo RAM_demo_inst (
.clock (tb_clk ),
.aclr (~tb_rst_n ),
.address (address ),
.data (data ),
.rden (rden ),
.wren (wren ),
.q (q_out )
);
// System initialization
initial tb_clk = 1'b1;
always #10 tb_clk = ~tb_clk;
initial begin
address = 8'd25;
data = 8'd51;
rden = 1'b0;
wren = 1'b0;
tb_rst_n = 1'b0;
#20;
tb_rst_n = 1'b1;
// 读操作
rden = 1'b1;
repeat (256) begin
address = address + 8'd1;
#(CYC_CLK);
end
rden = 1'b0;
#(500 * CYC_CLK);
// 写操作
wren = 1'b1;
repeat (256) begin
data = data + 8'd2;
address = address + 8'd1;
#(CYC_CLK);
end
wren = 1'b0;
#(500 * CYC_CLK);
// 读操作
rden = 1'b1;
repeat (256) begin
address = address + 8'd1;
#(CYC_CLK);
end
rden = 1'b0;
#(500 * CYC_CLK);
$stop;
end
endmodule
fifo_top.v
module fifo_top (
input clk ,
input rst_n ,
output [15:0] q ,
output rdempty ,
output [ 7:0] rdusedw ,
output wrfull ,
output [ 8:0] wrusedw
);
// Parameter definition
// Signal definition
reg [ 7:0] data ;
reg rdreq ;
reg wrreq ;
// Module calls
FIFO_512_8 FIFO_512_8_inst (
/*input */ .aclr (~rst_n ),// 复位信号,高电平有效
/*input [ 7:0]*/ .data (data ),// 写数据,8bits
/*input */ .rdclk (clk ),// 读时钟信号
/*input */ .rdreq (rdreq ),// 读使能信号,高电平读
/*input */ .wrclk (clk ),// 写时钟信号
/*input */ .wrreq (wrreq ),// 写使能信号,高电平写
/*output [15:0]*/ .q (q ),// 读数据,16bits
/*output */ .rdempty (rdempty ),// 读空使能,表示读的时候队列中是否为空,1表示空,0表示非空
/*output [ 7:0]*/ .rdusedw (rdusedw ),// 读余量,表示读的时候队列中有多少个16bits的数据
/*output */ .wrfull (wrfull ),// 写满使能,表示写的时候队列中是否写满了,1表示满,0表示非满
/*output [ 8:0]*/ .wrusedw (wrusedw ) // 写余量,表示写的时候队列中有多少个8bits的数据
);
// Logic description
// 读使能
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
rdreq <= 'd0;
end
else if (rdempty) begin
rdreq <= 'd0;
end
else begin
rdreq <= 'd1;
end
end
// 写使能
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
wrreq <= 'd0;
end
else if (wrfull) begin
wrreq <= 'd0;
end
else begin
wrreq <= 'd1;
end
end
// 写数据
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
data <= 'd20;
end
else if (wrreq) begin
if (data >= 255) begin
data <= 0;
end
else begin
data <= data + 'd2;
end
end
else begin
data <= 'd20;
end
end
endmodule
tb_fifo.v
`timescale 1ns/1ns
module tb_fifo;
// Parameter definition
parameter CYC_CLK = 20 ;
// Drive signal
reg tb_clk ;
reg tb_rst_n ;
// Observation signal
wire [15:0] tb_q ;
wire tb_rdempty ;
wire [ 7:0] tb_rdusedw ;
wire tb_wrfull ;
wire [ 8:0] tb_wrusedw ;
// Module calls
fifo_top U_fifo_top(
/*input */ .clk (tb_clk ),
/*input */ .rst_n (tb_rst_n ),
/*output [15:0]*/ .q (tb_q ),
/*output */ .rdempty (tb_rdempty ),
/*output [ 7:0]*/ .rdusedw (tb_rdusedw ),
/*output */ .wrfull (tb_wrfull ),
/*output [ 8:0]*/ .wrusedw (tb_wrusedw )
);
// System initialization
initial tb_clk = 1'b1;
always #10 tb_clk = ~tb_clk;
initial begin
tb_rst_n = 1'b0;
#20;
tb_rst_n = 1'b1;
#(200 * CYC_CLK);
$stop;
end
endmodule