FPGA设计中跨时钟域的异步处理

    在FPGA开发设计中,经常是多个时钟同时工作于同一模块中,不同时钟域的信号间要保证稳定通信,必须要处理好时序问题,也就是要充分考虑信号的建立和保持时间,以下是在设计中常用的单脉冲信号的处理方法:

`timescale 1 ps / 1 ps

module PULSE_GEN (
XRST ,
// (i) Reset Input ( Asynchronous )
CLK_I , // (i) Clock At Input Side
CLK_O , // (i) Clock At Output Side
PULSE_I , // (i) Pulse Input
PULSE_O // (o) Pulse Output
) ;

parameter P_TYPE = 8'd0 ;

//==========================================================
// Declare the port directions
//==========================================================

input XRST ; // (i) Reset Input ( Asynchronous )
input CLK_I ; // (i) Clock At Input Side
input CLK_O ; // (i) Clock At Output Side
input PULSE_I ; // (i) Pulse Input
output PULSE_O ; // (o) Pulse Output

//==========================================================
// Internal signals define
//==========================================================

reg r_PULSE_I ;
reg [2:0] r_PULSE_O ; // r_PULSE_O[0], r_pluse_o[1] Should Not Be Duplicated
// Synthesis Attribute MAX_FANOUT of r_PULSE_O is 9999;

//==========================================================
// RTL Body
//==========================================================

generate
if(P_TYPE == 0) begin :TYPE_0_PULSEGEN

//==========================================================
// Input Pulse Keep ( CLK_I domain )
//==========================================================
always @( posedge CLK_I or negedge XRST ) begin
if( !XRST ) begin
r_PULSE_I
<= 1'b0 ;
end else begin
if ( PULSE_I == 1'b1 ) begin
r_PULSE_I <= ~r_PULSE_I ;
end
end
end

//==========================================================
// Output Pulse Sync. And Generate ( CLK_O Domain )
//==========================================================
always @( posedge CLK_O or negedge XRST ) begin
if( !XRST ) begin
r_PULSE_O
<= 3'b000 ;
end else begin
r_PULSE_O
<= { r_PULSE_O[1:0] , r_PULSE_I } ;
end
end

assign PULSE_O = (r_PULSE_O[2] != r_PULSE_O[1] ) ; // 0 -> 1

end
endgenerate

endmodule
posted @ 2011-08-26 10:01  笨鸟多飞  阅读(1579)  评论(0编辑  收藏  举报