如题,Verilog实现,奉上拙见
//对1bit的脉冲信号进行展宽,转为32bit位宽,并产生有效信号;
module zhankuan(
input clk,
input rst_n,
input pulse_in,
output reg pulse_out,
output p_flag
);
//-------------------------------------------------------
reg in_r,in_rr;
reg [4:0] cnt;
//-------------------------------------------------------
//脉冲边缘检测
always @(posedge clk or negedge rst_n)
if(!rst_n) begin
in_r<=1'b0;
in_rr<=1'b0;
end
else begin
in_r<=pulse_in;
in_rr<=in_r;
end
assign p_flag=(~in_rr)&in_r;
//-------------------------------------------------------
//计数延长32个时钟
always @(posedge clk or negedge rst_n)
if(!rst_n)
pulse_out<=1'b0;
else if(p_flag)
pulse_out<=1'b1;
else if(cnt==5'd31)
pulse_out<=1'b0;
always @(posedge clk or negedge rst_n)
if(!rst_n)
cnt<=5'b0;
else if(pulse_out==1'b1)
if(cnt==5'd31)
cnt<=5'd0;
else
cnt<=cnt+1'b1;
//-------------------------------------------------------
endmodule