一段很长clk都不变化的信号很可能由于外界干扰 产生glitch
/ /shift in data
always @(posedge clk) begin
if( ~resetn)
data_sft <= 3'b0 ;
else
data_sft <= {data_sft[1:0], data};
end
//finding glitch
always @(posedge clk) begin
if(~resetn)
data_glitch_indi <= 1'b0;
else
begin
if((data_sft[2:0] == 3'b101) || (data_sft[2:0] == 3'b010))
data_glitch_indi <= 1'b1;
else
data_glitch_indi <= 1'b0;
end
end
//cancel glitch
assign data_out = data_sft[2] ^ data_glitch_indi;