forked from casper-astro/mlib_devel
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathclk_factors.py
52 lines (44 loc) · 1.65 KB
/
clk_factors.py
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
def clk_factors (clk_freq, target_freq, vco_min=650.0, vco_max=1150):
"""
PLLs/MMCM VCOs freq have a constrained target frequency range
The vco_min/max defaults are legacy from virtex 6 with the following note:
The vco is required to be between 600 and 1200 for the -1
speed grade vitrex 6, but it was found being close to the boundaries
causes issues, so the VCO is constrained to between 650 and 1150.
"""
bestM = 1
bestD = 1
bestDD = 1
bestDiff = 1000
Period = 1
PeriodHalf = 1
# the Multiply value is a even number because we need to divide by 1/2 of
# it to get the 200MHz clock, which is used for the QDR.
M = list(range(8,65,2))
D = list(range(2,128,1))
# If the input clock freq >= 315 then DD cant be 3 or 4.
if clk_freq >= 315:
DD = list(range(5,81,1))
else:
DD = list(range(1,81,1))
# x = [x 100*M(i)/D(j)/DD(k)];
for i in M:
for j in D:
for k in DD:
if (clk_freq*i/k < vco_max and clk_freq*i/k > vco_min):
diff = abs(clk_freq*i/j/k - target_freq);
if diff < bestDiff:
bestDiff = diff;
bestM = i;
bestD = j;
bestDD = k;
closest_freq = clk_freq * bestM / bestD / bestDD;
sys_clk_VCO = bestM * clk_freq / bestDD;
Periodns = (1/closest_freq)*1e3;
PeriodHalfns = Periodns/2;
#print closest_freq
#print sys_clk_VCO
#print Period
#print PeriodHalf
return float(bestM), float(bestD), bestDD, float(Periodns), float(PeriodHalfns)
#print clk_factors(200,161)