|
| 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