用了quartus II自带的宏模块 做了两个双口ram 实现缓存一行数据 我用modelsim一直
仿真不出来 testbench提示我 cnt没有定义 但是cnt是 程序里面的reg不是不用定义吗??
不知道写得对不对 是不是用两个ram就要使用乒乓操作??? 下面是例程
顶层文件--------------------------------------------------------------------------------
module m9k_two(
input [15:0] Data,
input clk_wr,
input clk_rd,
input rst_n,
input wren_1,
input wren_2,
input rden_1,
input rden_2,
output [15:0] set_out_1,
output [15:0] set_out_2);
//-----------------------------------------------------
wire [3:0] wraddress_1;
wire [3:0] rdaddress_1;
wire [3:0] wraddress_2;
wire [3:0] rdaddress_2;
wire [15:0] data_1;
wire [15:0] data_2;
//-----------------------------------------------------
//双口模块1
ram_1 ram_1_u(
.data(data_1),
.wraddress(wraddress_1),
.wren(wren_1),
.wrclock(clk_wr),
//---------------------------------
.rdaddress(rdaddress_1),
.rden(rden_1),
.rdclock(clk_rd),
.q(set_out_1)
);
//-----------------------------------------------------
//双口模块2
ram_2 ram_2_u(
.data(data_2),
.wraddress(wraddress_2),
.wren(wren_2),
.wrclock(clk_wr),
//---------------------------------
.rdaddress(rdaddress_2),
.rden(rden_2),
.rdclock(clk_rd),
.q(set_out_2)
);
//-----------------------------------------------------
//RAM控制模块
ram_top ram_top_u(
.clk_wr(clk_wr),
.clk_rd(clk_rd),
.data(Data),
.rst_n(rst_n),
.wraddress_1(wraddress_1),
.rdaddress_1(rdaddress_1),
// .wren_1(wren_1),
// .rden_1(rden_1),
.data_1(data_1),
.wraddress_2(wraddress_2),
.rdaddress_2(rdaddress_2),
// .wren_2(wren_2),
// .rden_2(rden_2),
.data_2(data_2)
);
endmodule
控制程序---------------------------------------------------------------------------------------------------
module ram_top(
input clk_wr,
input clk_rd,
input [15:0] data,
input rst_n,
output [3:0] wraddress_1,
output [3:0] rdaddress_1,
//output wren_1,
//output rden_1,
output [15:0] data_1,
output [3:0] wraddress_2,
output [3:0] rdaddress_2,
//output wren_2,
//output rden_2,
output [15:0] data_2
);
//-----------------------------------------------
//读地址控制模块
reg [3:0]wraddress_1_1;
reg [3:0]wraddress_2_2;
assign wraddress_1=wraddress_1_1;
assign wraddress_2=wraddress_2_2;
always@(posedge clk_wr or negedge rst_n)
begin
if(!rst_n)
begin
wraddress_1_1<=4'b0;
wraddress_2_2<=4'b0;
end
else
begin
wraddress_1_1<=wraddress_1_1+1;
wraddress_2_2<=wraddress_2_2+1;
end
end
//-----------------------------------------------
//写地址控制模块
reg [3:0]rdaddress_1_1;
reg [3:0]rdaddress_2_2;
assign rdaddress_1=rdaddress_1_1;
assign rdaddress_2=rdaddress_2_2;
always@(posedge clk_rd or negedge rst_n)
begin
if(!rst_n)
begin
rdaddress_1_1<=4'b0;
rdaddress_2_2<=4'b0;
end
else
begin
rdaddress_1_1<=rdaddress_1_1+1;
rdaddress_2_2<=rdaddress_2_2+1;
end
end
//-----------------------------------------------
//数据流
reg [15:0]data_1_1;
reg [15:0]data_2_2;
assign data_1=data_1_1;
assign data_2=data_2_2;
always@(posedge clk_wr or negedge rst_n)
begin
if(!rst_n)
begin
data_1_1<=16'b0;
data_2_2<=16'b0;
end
else
begin
if((cnt=1)||(cnt=2)||(cnt=3))
data_1_1<=data;
else
data_2_2<=data;
end
end
//-----------------------------------------------
//数据计数
reg [3:0] cnt;
always@(posedge clk_wr or negedge rst_n)
begin
if(!rst_n)
cnt<=4'b0;
else if(cnt<8)
cnt<=cnt+1;
else
cnt<=cnt;
end
endmodule
testbench 文件程序
`
timescale 1 ns/ 1 ns
module m9k_two_vlg_tst();
reg [15:0] Data;
reg clk_rd;
reg clk_wr;
reg rden_1;
reg rden_2;
reg rst_n;
reg wren_1;
reg wren_2;
wire [15:0] set_out_1;
wire [15:0] set_out_2;
m9k_two i1 (
.Data(Data),
.clk_rd(clk_rd),
.clk_wr(clk_wr),
.rden_1(rden_1),
.rden_2(rden_2),
.rst_n(rst_n),
.set_out_1(set_out_1),
.set_out_2(set_out_2),
.wren_1(wren_1),
.wren_2(wren_2)
);
//------------------------------------------------复位
initial
begin
rst_n=1'b1;
#10 rst_=1'b0;
end
//------------------------------------------------读时钟
initial
begin
clk_rd=1'b0;
forever
#10 clk_rd= ~clk_rd;
end
//------------------------------------------------写时钟
initial
begin
clk_wr=1'b0;
forever
#5 clk_wr= ~clk_wr;
end
//------------------------------------------------模块使能端
initial
begin
wren_1=1'b1;
rden_1=1'b1;
wren_2=1'b1;
rden_2=1'b1;
end
//------------------------------------------------
initial //顺序结构
begin
// wren = 0;
Data = 16'd0;
#10 Data = 16'd11;
#10 Data = 16'd22;
#10 Data = 16'd33;
#10 Data = 16'd44;
#10 Data = 16'd55;
#10 Data = 16'd66;
#10 Data = 16'd77;
end
endmodule
modelsim里面不管是REG还是WIRE,在使用前都需要有声明,就是在位置上要先声明再使用,不然就会有报错说未定义,然后又说重复定义
另外你那个cnt的判断语句能编译过去?!
一周热门 更多>