/*********************************************************
//description : this module will complete function of system init delay when power on
//author : raymon
//address : GDUT university of technology
//e-mail : 770811496@qq.com
//contact : 770811496
//time : 2015-1-31
**********************************************************/
`timescale 1ns/1ns
module system_init_delay
#(
parameter SYS_DELAY_TOP = 24'd2500000 //50ms system init delay
)
(
//-------------------------------------------
//global clock
input clk, //50MHz
input rst_n,
//system interface
output delay_done
);
//------------------------------------------
//Delay 50ms for steady state when power on
reg [23:0] delay_cnt = 24'd0;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
delay_cnt <= 0;
else if(delay_cnt < SYS_DELAY_TOP - 1'b1)
delay_cnt <= delay_cnt + 1'b1;
else
delay_cnt <= SYS_DELAY_TOP - 1'b1;
end
assign delay_done = (delay_cnt == SYS_DELAY_TOP - 1'b1)? 1'b1 : 1'b0;
endmodule
/*********************************************************
//description :this module will complete function of system init delay when power on
//author : raymon
//address : GDUT university of technology
//e-mail : 770811496@qq.com
//contact : 770811496
//time : 2015-1-31
**********************************************************/
`timescale 1ns/1ns
module system_ctrl(clk, rst_n, clk_ref, sys_rst_n);
//----------------------------------------------
//globol clock
input clk;
input rst_n;
//----------------------------------------------
//synced signal
output clk_ref; //clock output
output sys_rst_n; //system reset
//----------------------------------------------
//rst_n sync, only controlled by the main clk
reg rst_nr1, rst_nr2;
always @(posedge clk)
begin
if(!rst_n)
begin
rst_nr1 <= 1'b0;
rst_nr2 <= 1'b0;
end
else
begin
rst_nr1 <= 1'b1;
rst_nr2 <= rst_nr1;
end
end
//----------------------------------
//component instantiation for system_delay
wire delay_done; //system init delay has done
system_init_delay
#(
.SYS_DELAY_TOP (24'd2500000)
)
u_system_init_delay
(
//global clock
.clk (clk),
.rst_n (1'b1), //It don't depend on rst_n when power up
//system interface
.delay_done (delay_done)
);
assign clk_ref = clk;
assign sys_rst_n = rst_nr2 & delay_done; //active High
endmodule