-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcdc_synchronizer.v
53 lines (45 loc) · 1.25 KB
/
cdc_synchronizer.v
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
52
53
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2023 miya All rights reserved.
// ver. 2024/04/21
module cdc_synchronizer
#(
parameter DATA_WIDTH = 8,
parameter SYNC_TIMES = 3,
parameter SMOOTH_TIMES = 1
)
(
// clock domain (in) ------------------
input wire [(DATA_WIDTH-1):0] data_in,
// clock domain (out)------------------
output reg [(DATA_WIDTH-1):0] data_out,
input wire clk
// ------------------------------------
);
generate
genvar i;
wire [(SMOOTH_TIMES-1):0] smooth;
reg [(DATA_WIDTH-1):0] sync_data[SYNC_TIMES:0];
always @(posedge clk)
begin
sync_data[0] <= data_in;
end
for (i = 0; i < SYNC_TIMES; i = i + 1)
begin: sync_block
always @(posedge clk)
begin
sync_data[i + 1] <= sync_data[i];
end
end
for (i = 0; i < SMOOTH_TIMES; i = i + 1)
begin: smooth_block
assign smooth[i] = (sync_data[SYNC_TIMES - i - 1] == sync_data[SYNC_TIMES - i]);
end
always @(posedge clk)
begin
if (smooth == {SMOOTH_TIMES{1'b1}})
begin
data_out <= sync_data[SYNC_TIMES];
end
end
endgenerate
endmodule