Skip to content

Commit 26275d5

Browse files
committed
Was added script xilinx-pll-calc.php
1 parent fb8ca2a commit 26275d5

File tree

4 files changed

+232
-1
lines changed

4 files changed

+232
-1
lines changed

README.adoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ include::vergen-fpga.adoc[leveloffset=+2]
5454
=== Initial git settings of new EDA-related repository
5555

5656

57-
The `git-setting.sh` script create empty repo in speciffyed location and set up required setting for EDA-related projects (at the first one: the proper `.gitattributes` and `.gitignore` files)
57+
The `git-setting.sh` script create empty repo in specifyed location and set up required setting for EDA-related projects (at the first one: the proper `.gitattributes` and `.gitignore` files)
5858

5959
Detailed description:
6060
include::git-setting.adoc[leveloffset=+2]
6161

6262

63+
=== Find proper parameters for getting desired Frequency value by PLL/DCM block of Xilinx FPGA
64+
65+
The `xilinx-pll-calc.php` script print table of proper parameters for desired output frequency (based on known input frequency)
66+
67+
Detailed description:
68+
include::xilinx-pll-calc.adoc[leveloffset=+2]
6369

6470
== License
6571

image/xilinx-pll-calc.png

22 KB
Loading

xilinx-pll-calc.adoc

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
= Find proper parameters for getting desired Frequency by PLL/DCM block of Xilinx FPGA
2+
3+
The `xilinx-pll-calc.php` script print table of proper parameters for desired output frequency (based on known input frequency)
4+
5+
6+
== Usage
7+
8+
. Customize following variables `$F_input` (Hz), `$F_desired` (Hz) and `$precission` (%) in `xilinx-pll-calc.php`
9+
. Choice proper FPGA family, e.g.: `$FPGA = $SPARTAN6;`
10+
. Run it:
11+
+
12+
```
13+
php xilinx-pll-calc.php
14+
```
15+
+
16+
and looking for bold green string with exactly frequency value:
17+
image::image/xilinx-pll-calc.png[]
18+
19+
== Limitation
20+
21+
This script supports following family:
22+
* Xilinx Spartan-6
23+
* Xilinx Virtex-7
24+
* [Add your favourite FPGA. See next chapter]
25+
26+
27+
=== Adding new FPGA family
28+
29+
Xilinx, Altera, Lattice?... Everything can be supported!
30+
31+
The quick and dirty way to adding new family is filling associated array like that:
32+
```
33+
$VIRTEX7 = array(
34+
"FREQ_INP_MIN" => 19e6,
35+
"FREQ_INP_MAX" => 800e6,
36+
"FREQ_VCO_MIN" => 800e6,
37+
"FREQ_VCO_MAX" => 1600e6,
38+
"FREQ_OUT_MIN" => 6.25e6,
39+
"FREQ_OUT_MAX" => 800e6,
40+
"M_MIN" => 2,
41+
"M_MAX" => 64,
42+
"D_MIN" => 1,
43+
"D_MAX" => 128,
44+
"O_MIN" => 1,
45+
"O_MAX" => 56);
46+
```
47+
48+
Use this equation for explanation key name, like: M, D, O, FREQ_INP, FREQ_VCO, FREQ_OUT.
49+
```
50+
#######################
51+
######################## #
52+
# # Useful Folmulae #
53+
# M # for PLL Equation #
54+
# Fvco = Fin * - # #
55+
# D #######################
56+
# #
57+
# Fvco M #
58+
# Fout = ---- or Fout = Fin * ----- #
59+
# O D*O #
60+
# #
61+
###########################################
62+
```
63+
64+
65+
== Explanation of working
66+
67+
see the source code link:xilinx-pll-calc.php[]
68+
69+
== ToDo
70+
71+
* Mode of chaining two PLL in serial connection (for solving unresolved with single PLL Freq ratio)
72+
73+
== Known issues
74+
75+
not yet known

xilinx-pll-calc.php

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

0 commit comments

Comments
 (0)