|
发表于 2021-9-26 14:20:49
|
显示全部楼层
module top_module(
input clk,
input in,
input reset, // Synchronous reset
output done
);
reg [2:0]state,next_state;
reg [3:0]count;
parameter wAItt=1;
parameter start=2;
parameter stop=3;
always@(posedge clk)
if(reset)
state<=waitt;
else state<=next_state;
always@(*)
begin
case(state)
start: if(count==4'd7)
next_state=stop;
else next_state=start;
stop:
next_state=waitt;
waitt: if(in==1'b0)
next_state=start;
else next_state=waitt;
default: next_state=waitt;
endcase
end
always@(posedge clk)
begin
if(reset||done==1)
count<=0;
else if(state==start)
count<=count+1'b1;
else count<=count;
end
always@(posedge clk)
if(reset)
done <= 1'b0;
else if(state == stop && in == 1'b1)
done <= 1'b1;
else
done <= 1'b0;
endmodule |
|