Vorilog利用PLL实现双脉冲输出
近期项目需要做一个双脉冲输出实验,利用Verilog的PLL产生40MHz时钟信号,利用此信号产生脉宽为25ns,间隔75ns(两上升沿相隔100ns)的双脉冲,周期为20微秒,如下图:
模块输入为系统时钟clk,复位rst_n,输出信号pulse_out,系统时钟40MHz,则周期T=1/40MHz=25ns.
20微秒计数:(20*10^-6)*40000000-1=799
25ns:1
100ns:4
125ns:5
`timescale 1ns / 1ps
// Module Name: clk_div
//////////////////////产生25ns,间隔75ns的双脉冲,周期为20微秒////////////////////////////////////////////////////////////
module clk_div(
clk,
rst_n,
pulse_out
);
// PORT declarations //==========================================
input clk;
input rst_n;
output pulse_out;
//寄存器定义
reg pulse_out;
reg [9:0] counter;
//计数器计数
[email protected](posedge CLK_OUT1 or negedge rst_n) //检测时钟的上升沿或者下降沿
begin
if(~rst_n) //复位信号低有效
counter <= 0; //计数器清零
else if(counter == 10'd799) //40MHz,20微秒计数
counter <= 0;
else
counter<=counter + 1'b1; //计数器加1
end
//脉冲输出
[email protected](posedge CLK_OUT1 or negedge rst_n)
begin
if(~rst_n)
pulse_out<=0;
else if(counter == 10'd0)
pulse_out <= 1'b1;
else if(counter == 1)
pulse_out <= 1'b0;
else if(counter == 4) //100ns时置1
pulse_out <= 1'b1;
else if(counter == 5)
pulse_out <= 1'b0;
else
pulse_out <= pulse_out;
end
//--//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG
pll_ip instance_name ///(例化PLL模块)
(// Clock in ports
.CLK_IN1(clk), // IN
// Clock out ports
.CLK_OUT1(CLK_OUT1)); // OUT
// INST_TAG_END ------ End INSTANTIATION Template ---------
endmodule
其中本次学习添加cdc文件后用Chipscope观察信号
1.选择触发器位宽:这里选择为1
2.数据长度,因为这里计数只到799,1024就足够。
3.在此处选择时钟信号端口和触发信号
随后就可以在Chipscope中观察双脉冲产生得是否准确了。