always @( posedge clk or negedge rst_n )
if ( !rst_n )
begin
state <= 1'b0;
cnt <= 0;
end
else
case(state)
1'b0:begin
if(in==0)
begin
state <= 1'b1;
cnt <= 0;
end
else
begin
state <= 1'b0;
if(cnt<THRESHOLD)cnt <= cnt+1;
end
end
1'b1:begin
if(in==0)
begin
state <= 1'b1;
if(cnt<THRESHOLD) cnt <= cnt+1;
end
else
begin
state <= 1'b0;
cnt <= 0;
end
end
endcase
always @( posedge clk or negedge rst_n )
if ( !rst_n )
out <= 1;
else if (cnt==THRESHOLD-1)
out <= in;
endmodule
(
input rst_n,
input clk,//64KHz
input in,
output reg out
);
parameter CNT_WITDH = 8;
parameter THRESHOLD = 192;
reg [CNT_WITDH:0] cnt;
reg state;
always @( posedge clk or negedge rst_n )
if ( !rst_n )
begin
state <= 1'b0;
cnt <= 0;
end
else
case(state)
1'b0:begin
if(in==0)
begin
state <= 1'b1;
cnt <= 0;
end
else
begin
state <= 1'b0;
if(cnt<THRESHOLD)cnt <= cnt+1;
end
end
1'b1:begin
if(in==0)
begin
state <= 1'b1;
if(cnt<THRESHOLD) cnt <= cnt+1;
end
else
begin
state <= 1'b0;
cnt <= 0;
end
end
endcase
always @( posedge clk or negedge rst_n )
if ( !rst_n )
out <= 1;
else if (cnt==THRESHOLD-1)
out <= in;
endmodule
一周热门 更多>