//再来一次试一试
//当S的状态发生翻转时,pulseout发出一个脉冲
module pulse ( clk ,rst,S ,pulseout );
input clk ;
wire clk ;
input S;
input rst ;
output pulseout;
reg pulseout;
reg b;//分频中间变量
reg S_delay;
reg [2:0] cnt= 0 ;
reg clkout ;
always @ ( posedge clk or negedge rst )
begin
if ( rst == 1'b0 )begin
cnt <= 0 ;
b <= 1'b0;
end
else begin
if (cnt == 3'd4 ) begin
cnt <= 1'b0;
b <= ~b;
end
else begin
cnt <= cnt+1'b1;
end
end
end
always @(posedge b) begin
S_delay <= S;
pulseout <= S ^ S_delay;
end
endmodule