对于FPGA芯片而言,上电之后最开始的一段时间是特别不稳定的,所以在FPGA程序中添加一个上电之后的延时程序,这个是很有必要的。
然而我们常用的是使用PLL中的 locked 信号,来判断是否初始化成功,但是这个初始化仅仅是对于PLL这个IP核所使用的,所以这个信号还是不够具有权威性。
根据上述问题,相对较好的方法是:在程序开始跑之前,就对程序进行延时操作。
首先先来一个PLL的顶层模块:其中包括了两个部分:PLL_IP核的初始化,初始化之后的延时。
module PLL
(
input wire ext_clk, //G21 , CLK_50M
input wire ext_rst_n, //E4
// output wire sys_rst_n,
output wire clk0,
output wire clk1,
output wire clk2,
output wire clk3,
output wire clk4,
output reg rst_D=0
);
wire sys_rst_n;
wire locked;
reg locked_temp;
reg locked_temp1;
reg [8:0] cnt_rst=255;
reg [8:0] cnt_rst1=255;
Button RST
(
.clk_in_Button(ext_clk) ,
.input_Button(ext_rst_n) ,
.POL_en_in(0) ,
.POL_en_out(1) ,
.output_Button(sys_rst_n)
);
PLL_sys PLL_sys_inst (
.areset ( sys_rst_n ),
.inclk0 ( ext_clk ),
.c0 ( clk0 ),
.c1 ( clk1 ),
.c2 ( clk2 ),
.c3 ( clk3 ),
.c4 ( clk4 ),
.locked ( locked )
);
always@(posedge ext_clk)
begin
locked_temp <=locked;
locked_temp1<=locked_temp;
end
always@(posedge ext_clk) begin
if(locked_temp1==0&&locked_temp==1)
cnt_rst<=0;
else if(cnt_rst==255)
begin
if(cnt_rst1==255)
cnt_rst<=cnt_rst;
else
cnt_rst<=0;
end
else
cnt_rst<=cnt_rst+1;
end
always@(posedge ext_clk) begin
if(locked_temp1==0&&locked_temp==1)
cnt_rst1<=0;
else if(cnt_rst1==255)
cnt_rst1<=cnt_rst1;
else if(cnt_rst==255)
cnt_rst1<=cnt_rst1+1;
end
always@(posedge ext_clk) begin
if(cnt_rst1==255)
rst_D<=0;
else
rst_D<=1;
end
endmodule
在这个模块中还有一个模块,我把这个模块的代码也附带上。
`timescale 1ns / 1ps
module Button
(
input wire clk_in_Button,
input wire input_Button,
input wire POL_en_in, //select H/L INTPUT FLAG
input wire POL_en_out, //select H/L OUTPUT FLAG
output reg output_Button=0
);
//
reg[7:0] cont =0;
reg B_temp1 =0;
reg B_temp2 =0;
//
always@(posedge clk_in_Button)
begin B_temp1<=input_Button; B_temp2<=B_temp1; end
always@(posedge clk_in_Button)
begin
if((B_temp2==POL_en_in)&&(B_temp1==POL_en_in))
begin
if(cont==255) cont<=cont;
else if(cont==250) cont<=255;
else cont<=cont+1;
end
else
cont<=0;
end
always@(posedge clk_in_Button)
if(cont==250) output_Button<=POL_en_out;
else output_Button<=!POL_en_out;
endmodule
经过这两个模块之后,对于整个系统,上电也差不多就结束了,而且相对比较稳定,在发出程序执行的复位信号(在未完成的时候是拉高的,完成之后是拉低的)