-
Notifications
You must be signed in to change notification settings - Fork 4
/
xilinx-pll-calc.php
150 lines (124 loc) · 4.64 KB
/
xilinx-pll-calc.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* A PHP calculator for desired frequency by PLL/DCM onto Xilinx FPGA
* @package
* @author Dmitry Murzinov ([email protected])
* @link : https://github.com/iDoka/eda-scripts
* @version 1.0
*/
#######################
######################## #
# # Useful Folmulae #
# M # for PLL Equation #
# Fvco = Fin * - # #
# D #######################
# #
# Fvco M #
# Fout = ---- or Fout = Fin * ----- #
# O D*O #
# #
###########################################
# Example of usage:
# $ php xilinx-pll-calc.php
#
$F_input = 50e6; // Hz
$F_desired = 48e6; // Hz
$precission = 0.5; // %
//$tolerance=1; // %
// check if CLI-mode
if (PHP_SAPI != "cli") {
exit;
}
define('__ROOT__', dirname(__FILE__));
//require_once(__ROOT__.'/PLL-func.php');
/*
// parsing arg as filename
if ($argc > 1) {
$filename = $argv[1];
$contents = file_get_contents($filename);
$contents = utf8_encode($contents);
$pinout = json_decode($contents,TRUE);
}
else {
echo "Usage tool in CLI:\n\t$ php xilinx-pll-calc.php\n";
exit;
}
*/
###########################################
### Store of settings different PLL
$SPARTAN6 = array( // -3 grade -2 grade -1L grade
"FREQ_INP_MIN" => 19e6,
"FREQ_INP_MAX" => 450e6, // 540 450 300
"FREQ_VCO_MIN" => 400e6,
"FREQ_VCO_MAX" => 1000e6, // 1080 1000 1000
"FREQ_OUT_MIN" => 3.125e6,
"FREQ_OUT_MAX" => 950e6, // 1080 950 500
"M_MIN" => 1,
"M_MAX" => 64,
"D_MIN" => 1,
"D_MAX" => 128,
"O_MIN" => 1,
"O_MAX" => 52);
$VIRTEX7 = array( // -3 grade -2 grade -1 grade
"FREQ_INP_MIN" => 19e6,
"FREQ_INP_MAX" => 800e6, // 1066 933 800
"FREQ_VCO_MIN" => 800e6,
"FREQ_VCO_MAX" => 1600e6, // 2133 1866 1600
"FREQ_OUT_MIN" => 6.25e6,
"FREQ_OUT_MAX" => 800e6, // 1066 933 800
"M_MIN" => 2,
"M_MAX" => 64,
"D_MIN" => 1,
"D_MAX" => 128,
"O_MIN" => 1,
"O_MAX" => 56);
###########################################
/*
Stages:
1. Check input range
2. Check output range
3. Pick up 3 cycles for proper Fvco and Fout with desired tolerance
4. If unsuccessful -> goto chain of 2 serial PLL connection
*/
// Pick up desired FPGA family:
$FPGA = $SPARTAN6;
########## 1. Check input range ##########
if (($FPGA["FREQ_INP_MIN"] > $F_input) | ($FPGA["FREQ_INP_MAX"] < $F_input)) {
echo "CAUTION: Input frequency out of range!".PHP_EOL;
exit;
}
########## 2. Check output range ##########
if (($FPGA["FREQ_OUT_MIN"] > $F_desired) or ($FPGA["FREQ_OUT_MAX"] < $F_desired)) {
echo "CAUTION: Output frequency out of range!".PHP_EOL;
exit;
}
$tolerance = $precission / 100; // parts
echo PHP_EOL."Settings:".PHP_EOL."\tFinput: $F_input Hz".PHP_EOL."\tFoutput: $F_desired Hz (desired)".PHP_EOL.PHP_EOL;
//echo "\e[7m M\tD\tO \tFout (Error)\e[0m".PHP_EOL;
echo "\e[7m M D O Fout (Error)\e[0m".PHP_EOL;
echo "===== ===== ========= =========== =======".PHP_EOL;
########## 3. Pick up 3 cycles for proper Fvco and Fout with desired tolerance ##########
for ($M=$FPGA["M_MIN"]; $M<=$FPGA["M_MAX"]; $M++) {
for ($D=$FPGA["D_MIN"]; $D<=$FPGA["D_MAX"]; $D++) {
$F_VCO = $F_input * $M/$D;
if (($FPGA["FREQ_VCO_MIN"] <= $F_VCO) and ($FPGA["FREQ_VCO_MAX"] >= $F_VCO)) {
//echo "M=$M \tD=$D \tVCO=$F_VCO".PHP_EOL;
for ($O=$FPGA["O_MIN"]; $O<=$FPGA["O_MAX"]; $O++) {
$F_output = $F_input * $M/$D/$O;
if ((($F_desired*(1-$tolerance)) <= $F_output) and ($F_output <= ($F_desired*(1+$tolerance)))) {
$deviation = ceil(abs($F_output/$F_desired-1)*100*100)/100;
if ($F_desired == $F_output) {
echo "\e[1m\e[32m $M\t$D\t$O \t$F_output bingo\e[0m".PHP_EOL;
} else {
$F_output = round($F_output);
echo " $M\t$D\t$O \t$F_output ($deviation%)".PHP_EOL;
}
}
}
}
}
}
########## 4. chain of 2 serial PLL connection ##########
# To do ...
###########################################################################################################
?>