Debian Codegraph @

hdl/fpga/ip/nuand/vctcxo_tamer/vhdl/tb/asvtx12a384m_model.vhd

raw
1 -- Copyright (c) 2015 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20 library ieee;
21 use ieee.std_logic_1164.all;
22 use ieee.numeric_std.all;
23 use ieee.math_real.all;
24
25 library std;
26 use std.env.all;
27
28 entity asvtx12a384m_model is
29 port(
30 vcon : in real; -- control voltage
31 clock : out std_logic -- output clock
32 );
33 end entity;
34
35 architecture arch of asvtx12a384m_model is
36
37 -- Control Voltage Tolerances
38 constant VCON_MIN : real := 0.4;
39 constant VCON_MAX : real := 2.4;
40
41 -- Nominal output frequency
42 constant FREQ_NOMINAL : real := 38.4e6;
43
44 -- Frequency stability tolerance
45 constant PPM_STABILITY_MIN : real := -2.0;
46 constant PPM_STABILITY_MAX : real := 2.0;
47
48 -- Frequency Tuning Tolerances
49 constant PPM_VCON_MIN_MIN : real := -5.0;
50 constant PPM_VCON_MIN_MAX : real := -9.5;
51 constant PPM_VCON_MAX_MIN : real := 5.0;
52 constant PPM_VCON_MAX_MAX : real := 9.5;
53
54 -- Given a frequency, compute the half period time
55 function half_clk_per( freq : real ) return time is
56 begin
57 return ( (0.5 sec) / real(freq) );
58 end function;
59
60 -- Compute a random PPM in the given range
61 function random_ppm( ppm_min : real; ppm_max : real ) return real is
62 variable seed1 : positive;
63 variable seed2 : positive;
64 variable rand : real;
65 begin
66 uniform(seed1, seed2, rand);
67 return (rand*(ppm_max-ppm_min) + ppm_min);
68 end function;
69
70 -- Given a Vcon voltage, calculate the minimum possible PPM error
71 function vcon_ppm_min_calc( vcon : real ) return real is
72 variable slope : real := 0.0;
73 variable intercept : real := 0.0;
74 variable rv : real := 0.0;
75 begin
76 slope := (PPM_VCON_MAX_MIN-PPM_VCON_MIN_MIN)/(VCON_MAX-VCON_MIN);
77 intercept := PPM_VCON_MAX_MIN-(slope*VCON_MAX);
78 if( (vcon >= VCON_MIN) and (vcon <= VCON_MAX) ) then
79 rv := ( (slope * vcon) + intercept );
80 else
81 report "vcon_ppm_min_calc: vcon out of recommended range. Returning 0."
82 severity warning;
83 rv := 0.0;
84 end if;
85
86 return rv;
87 end function;
88
89 -- Given a Vcon voltage, calculate the maximum possible PPM error
90 function vcon_ppm_max_calc( vcon : real ) return real is
91 variable slope : real := 0.0;
92 variable intercept : real := 0.0;
93 variable rv : real := 0.0;
94 begin
95 slope := (PPM_VCON_MAX_MAX-PPM_VCON_MIN_MAX)/(VCON_MAX-VCON_MIN);
96 intercept := PPM_VCON_MAX_MAX-(slope*VCON_MAX);
97 if( (vcon >= VCON_MIN) and (vcon <= VCON_MAX) ) then
98 rv := ( (slope * vcon) + intercept );
99 else
100 report "vcon_ppm_max_calc: vcon out of recommended range. Returning 0."
101 severity warning;
102 rv := 0.0;
103 end if;
104
105 return rv;
106 end function;
107
108 -- Given a Vcon PPM and a frequency stability PPM, compute the freuqency
109 function freq_calc( vcon_ppm : real; tol_ppm : real ) return real is
110 variable rv : real;
111 begin
112 -- Frequency with Vcon PPM error applied
113 rv := ( FREQ_NOMINAL * ( 1.0 + (vcon_ppm/1.0e6) ) );
114 -- Apply frequency stability tolerance
115 rv := ( rv * (1.0 + (tol_ppm/1.0e6)) );
116 return rv;
117 end function;
118
119 signal freq : real;
120 signal half_per : time := 13.021 ns;
121 signal clock_i : std_logic := '1';
122
123 begin
124
125 -- i don't think the frequency is changing at all
126 -- even though vcon is changing
127
128 comb_proc : process( all )
129 variable tuning_ppm : real := 0.0;
130 variable stability_ppm : real := 0.0;
131 variable total_ppm : real := 0.0;
132 begin
133 stability_ppm := random_ppm(PPM_STABILITY_MIN, PPM_STABILITY_MAX);
134 report "Setting stability error to: " & real'image(stability_ppm) & " PPM.";
135 tuning_ppm := random_ppm(vcon_ppm_min_calc(vcon), vcon_ppm_max_calc(vcon));
136 report "Setting tuning error to: " & real'image(tuning_ppm) & " PPM.";
137
138 freq <= freq_calc(tuning_ppm, stability_ppm);
139 half_per <= half_clk_per(freq);
140 report "freq_error=" & real'image(freq-FREQ_NOMINAL);
141 report "freq=" & real'image(freq);
142 end process;
143
144 clock_i <= not clock_i after half_per;
145 clock <= clock_i;
146
147 end architecture;