begin
if(bfw==1)
cnt<=1;
else
cnt<=cnt+1;
end
需求是bfw=1时才开始计数,这个地方明显不对,如果bfw从一开始就不等于1,不是也会计数;bfw=1时只是重新设置了cnt的值为1;
应该这样:
begin
if(bfw==1)
cnt_en<=1'b1;
cnt <= 1; //如果需要在bfw等于1时将cnt值置为1的话
else
cnt_en<=cnt_en;
end
always @(posedge clk)
begin
if(cnt_en == 1'b1)
cnt <= cnt+1'b1;
else;
end
reg [12:0] cnt_reg;
always@(posedge clk)
begin
cnt_reg <= {cnt_reg[12:1],bfw}
end
always@(posedge clk or rst)
begin
if(rst == 1'b1) begin
ctr<= 1'b0;
end
else if (cnt_reg == 13'0000000100000 ) begin
ctr<= 1'b1;
end
else if (cnt_reg == 13'1000000000000) begin
ctr<= 1'b0;
end
end