|
在isplever中编写程序,对一路数字信号采样,检查它的跳变,我的做法如下:
检测待测信号的上升延次数,在读信号rd有效时,读取计数值,若计数值为0,则待测信号没有跳变,计数不为0则待测信号有跳变,我的代码如下:
module datasmp(reset,rd,clk,data1,dout1);
input reset,clk,rd,data1;
output [7:0] dout1;
//output clr;
reg [7:0] dcnt;
//reg clr;
wire clr;
reg temp1, temp2;
reg [1:0] c;
always@(posedge clk)
begin
if(!rd)
begin
c<=0;
end
else
begin
if(c<2)
c <= c+1;
end
end
assign clr = ~c[0];
always@(posedge clk) //count data pulse
begin
if (!reset)
dcnt<=0;
else
begin
temp1<=temp2;
temp2<=data1;
if(temp1 ^ temp2)
dcnt <= dcnt+1;
if(dcnt>200)
dcnt <= 200;
if(!clr)
dcnt <= 0;
end
end
assign dout1 = (!rd)?dcnt:8'hZZ;
endmodule
在quartus II中仿真时可以得到正确结果,但在isplever中仿真时要写testbench,我的testbench代码如下,
`timescale 1ns/1ns
`include "datasmp.v"
module datasmp_tb;
reg reset,clk,rd,data1;
wire [7:0] dout1;
parameter DELY=10;
datasmp mydatasmp(reset,clk,rd,data1,dout1);
always #(DELY/2) clk=~clk;
//always #(DELY*20) data1=~data1;
initial
begin
clk =0; reset =0; rd=1;data1=1;
#(DELY*10) reset=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) rd=0;data1=0;
#(DELY*20) rd=1;data1=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*20) data1=0;rd=0;
#(DELY*20) data1=1;rd=1;
#(DELY*20) data1=0;
#(DELY*20) data1=1;
#(DELY*500) $finish;
end
initial $monitor($time,,,"%d %d %b %d %d",reset,clk,rd,data1,dout1);
endmodule
仿真时老出现错误: Error loading design
# Error: Error loading design
# Pausing macro execution
# MACRO ./datasmp_tb_tff.udo PAUSED at line 4
我是新手,对testbench的规范不熟悉,请各位高手帮我看看,该如何改正,谢谢!
[em13] |
|