设计一个计数器,使得flag信号在达到1s时置1,其余时间为0。
reg [27:0] cnt;
reg flag;
always @ (posedge clk)
begin
if (!rstn)
cnt <= 0;
else if (cnt == 28'd50000000)
cnt <= 0;
else
cnt <= cnt + 1;
end
always @ (posedge clk)
begin
if (!rstn)
flag <= 1'b0;
else if (cnt == 28'd50000000)
flag <= 1'b1;
else
flag <= 1'b0;
end
设计一个计数器,使得flag信号在达到1s时置1,其余时间为0。
reg [27:0] cnt;
reg flag;
always @ (posedge clk)
begin
if (!rstn)
cnt <= 0;
else if (cnt == 28'd50000000)
cnt <= 0;
else
cnt <= cnt + 1;
end
always @ (posedge clk)
begin
if (!rstn)
flag <= 1'b0;
else if (cnt == 28'd50000000)
flag <= 1'b1;
else
flag <= 1'b0;
end