|
我在quatus里仿真就没问题,而在Modelsim仿真不出来(编译通过),帮我看看我的testbench哪写错了
我的testbench代码:
`timescale 1ns/1ns
module shideng_tb ( );
parameter period=20;
// input port
reg clk;
reg rst_b;
//output port
wire LED_1;
wire LED_2;
wire LED_3;
wire LED_4;
// DUT:device under test
shideng dut(
.clk(clk),
.rst_b(rst_b),
.LED_1(LED_1),
.LED_2(LED_2),
.LED_3(LED_3),
.LED_4(LED_4)
);
// clock
initial
begin
clk=0;
forever
#(period/2) clk=~clk;
end
//reset
initial
begin
reset_test(50);
end
// task
task reset_test;
input [15:0]reset_time; //reset time
begin
rst_b=0;
#(reset_time) rst_b=1;
end
endtask
endmodule
源程序代码:
module shideng (LED_1, LED_2, LED_3, LED_4, clk, rst_b);
input clk, rst_b;
output LED_1, LED_2, LED_3, LED_4;
reg LED_1, LED_2, LED_3, LED_4;
reg clk_2s, clk_1s, clk_half, clk_qtr;
reg [27:0] DATA_NUM1, DATA_NUM2, DATA_NUM3, DATA_NUM4;
always@(negedge rst_b or posedge clk)
begin
if(!rst_b)
DATA_NUM1<=0;
else if(DATA_NUM1==28'h8)
begin
DATA_NUM1<=0;
clk_2s<=~clk_2s;
end
else
begin
clk_2s<=clk_2s;
DATA_NUM1<=DATA_NUM1+1;
end
end
always@(negedge rst_b or posedge clk)
begin
if(!rst_b)
DATA_NUM2<=0;
else if(DATA_NUM2==28'h4)
begin
DATA_NUM2<=0;
clk_1s<=~clk_1s;
end
else
begin
clk_1s<=clk_1s;
DATA_NUM2<=DATA_NUM2+1;
end
end
always@(negedge rst_b or posedge clk)
begin
if(!rst_b)
DATA_NUM3<=0;
else if(DATA_NUM3==28'h2)
begin
DATA_NUM3<=0;
clk_half<=~clk_half;
end
else
begin
clk_half<=clk_half;
DATA_NUM3<=DATA_NUM3+1;
end
end
always@(negedge rst_b or posedge clk)
begin
if(!rst_b)
DATA_NUM4<=0;
else if(DATA_NUM4==28'h1)
begin
DATA_NUM4<=0;
clk_qtr<=~clk_qtr;
end
else
begin
clk_qtr<=clk_qtr;
DATA_NUM4<=DATA_NUM4+1;
end
end
always@(posedge clk_2s or negedge rst_b)
begin
if(!rst_b)
LED_1<=1;
else
LED_1<=~LED_1;
end
always@(posedge clk_1s or negedge rst_b)
begin
if(!rst_b)
LED_2<=1;
else
LED_2<=~LED_2;
end
always@(posedge clk_half or negedge rst_b)
begin
if(!rst_b)
LED_3<=1;
else
LED_3<=~LED_3;
end
always@(posedge clk_qtr or negedge rst_b)
begin
if(!rst_b)
LED_4<=1;
else
LED_4<=~LED_4;
end
endmodule
Quatus波形正确
modelsim输出全为1 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?我要注册
x
|