|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
自己写了一段公用比较器实现记得时间差的程序,但是仿真结果不多,下载到硬件测量结果也不对,求高手帮忙
//计时程序2012/3/1
module huoju_caiji(
input s01,ter02,ter03, //输入点火信号
input clk,
input rst, //复位信号
output [31:0] deltat1,
output [31:0] deltat2); //输出时间差
reg [31:0] count;
reg [31:0] count1;
reg [31:0] count2; //计数计一小时D693A400
reg [31:0] count3;
reg [31:0] tempt1;
reg [31:0] tempt2;
reg flag1;
reg flag2;
reg flag3;
reg i;
//基准计时时间
always @ (posedge clk or negedge rst)
begin
if(!rst)
begin
count<=32’d0;end
else
begin count<=count+1'b1; end
end
//开始计时时间1结束时间2
always @ (posedge s01 or posedge ter02 or negedge rst )
begin
if(!rst)
begin
count1<=32'd0;
flag1<=1'b0;
count2<=32'd0;
flag2<=1'b0;
i<=1'b0;
end
else if(s01||ter02==1'b1)
begin
i<=i+1'b1;
end
case(i)
1'b0:begin
count2<=count;
flag2<=1'b1;
end
1'b1:begin
count1<=count;
flag1<=1'b1;
end
endcase
end
//结束计时时间3
always @ (posedge ter03 or negedge rst )
begin
if(!rst)
begin
count3<=32'd0;
flag3<=1'b0;
end
else
begin
count3<=count;
flag3<=1'b1;
end
end
always @ (posedge clk or negedge rst)
begin
if(!rst)
begin
tempt1<=32'd0;
tempt2<=32'd0;
end
else if({flag2,flag3}==2'b11)
begin
case({flag2,flag3})
2'b01: begin tempt1<=32'd0;
tempt2<=(count3-count1);
end
2'b10: begin tempt1<=(count2-count1);
tempt2<=32'd0;
end
2'b11: begin tempt1<=(count2-count1);
tempt2<=(count3-count1);
end
default begin tempt1<=32'd0;
tempt2<=32'd0;
end
endcase
end
end
assign deltat1=tempt1;
assign deltat2=tempt2;
endmodule |
|