-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdc_sync_with_rst.sv
51 lines (38 loc) · 2.08 KB
/
cdc_sync_with_rst.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*===============================================================================================================================
Module : CDC Synchronizer
Description : CDC Synchronizer synchronizes 1-bit signal from source clock domain safely to destination clock domain.
Developer : Mitu Raj, chip@chipmunklogic.com at Chipmunk Logic ™, https://chipmunklogic.com
Notes : Attribute ASYNC_REG used to PAR the flops together in Xilinx FPGAs.
License : Open-source.
Date : Aug-17-2022
===============================================================================================================================*/
/*-------------------------------------------------------------------------------------------------------------------------------
C D C S Y N C H R O N I Z E R
-------------------------------------------------------------------------------------------------------------------------------*/
module cdc_sync_with_rst #(
// Configurable parameters
parameter STAGES = 2 // No. of flops in the chain, min. 2
)
(
input logic clk , // Clock @ destination clock domain
input logic rstn , // Sync Reset @ destination clock domain
input logic i_sig , // Input signal, asynchronous
output logic o_sig_sync // Output signal synchronized to clk
) ;
(* ASYNC_REG = "TRUE" *)
logic [STAGES-1: 0] sync_ff ;
// Synchronizing logic
always @(posedge clk) begin
if (!rstn) begin
sync_ff <= '0 ;
end
else begin
sync_ff <= {sync_ff [STAGES-2 : 0], i_sig} ;
end
end
// Synchronized signal
assign o_sig_sync = sync_ff [STAGES-1] ;
endmodule
/*-------------------------------------------------------------------------------------------------------------------------------
C D C S Y N C H R O N I Z E R
-------------------------------------------------------------------------------------------------------------------------------*/