本帖最后由 宝挖小子 于 2020-7-16 17:14 编辑
各位大神,如题,我要做一个计数器复位动作,但是有时会出现下图 所示异常,这是为啥啊?代码哪里有问题,怎么改啊?
代码如下:
always @(negedge clk_10mhz) begin
if(rst) begin
s_resync_cnt<=24'd0;
s_resync<=1'd1;
end else begin
if ((!s_pps_pos[0] && s_pps) ) begin //或者s_pps上升沿
if(s_resync_cnt<24'd999_0000 && s_resync_cnt>24'd0)begin
s_resync<=1'd1;
end else begin
s_resync<=1'd0;
end
s_resync_cnt<=24'd0;
end else begin
s_resync_cnt<=s_resync_cnt+24'd1;
if(s_resync_cnt<(24'd1000_5000)) begin
s_resync<=1'd0;
end else if(s_resync_cnt<(24'd1000_5020)) begin //rst state
s_resync<=1'd1;
end else begin
s_resync_cnt<=(24'd1000_5021);
s_resync<=1'd0;
end
end
end
end
always @(posedge clk_10mhz) begin
if (rst) begin
s_pps_pos<=3'd0;
end else begin
s_pps_pos[0]<=s_pps_pos[1];
s_pps_pos[1]<=s_pps_pos[2];
s_pps_pos[2]<=s_pps;
end
end
|