OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [rtl/] [vlib/] [xlib/] [s7_cmt_sfs_gsim.vhd] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 wfjm
-- $Id: s7_cmt_sfs_gsim.vhd 675 2015-05-08 21:05:08Z mueller $
2 29 wfjm
--
3
-- Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    s7_cmt_sfs - sim
16
-- Description:    Series-7 CMT  for simple frequency synthesis
17
--                 simple vhdl model, without Xilinx UNISIM primitives
18
--
19
-- Dependencies:   -
20
-- Test bench:     -
21
-- Target Devices: generic Series-7
22 30 wfjm
-- Tool versions:  xst 14.5; viv 2014.4; ghdl 0.29
23 29 wfjm
--
24
-- Revision History: 
25
-- Date         Rev Version  Comment
26
-- 2013-09-28   535   1.0    Initial version (derived from dcm_sfs_gsim)
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
 
32
use work.slvtypes.all;
33
 
34
entity s7_cmt_sfs is                    -- 7-Series CMT for simple freq. synth.
35
  generic (
36
    VCO_DIVIDE : positive := 1;         -- vco clock divide
37
    VCO_MULTIPLY : positive := 1;       -- vco clock multiply 
38
    OUT_DIVIDE : positive := 1;         -- output divide
39
    CLKIN_PERIOD : real := 10.0;        -- CLKIN period (def is 10.0 ns)
40
    CLKIN_JITTER : real := 0.01;        -- CLKIN jitter (def is 10 ps)
41
    STARTUP_WAIT : boolean := false;    -- hold FPGA startup till LOCKED
42
    GEN_TYPE : string := "PLL");        -- PLL or MMCM
43
  port (
44
    CLKIN : in slbit;                   -- clock input
45
    CLKFX : out slbit;                  -- clock output (synthesized freq.) 
46
    LOCKED : out slbit                  -- pll/mmcm locked
47
  );
48
end s7_cmt_sfs;
49
 
50
 
51
architecture sim of s7_cmt_sfs is
52
 
53
  signal CLK_DIVPULSE : slbit := '0';
54
  signal CLKOUT_PERIOD : time := 0 ns;
55
  signal R_CLKOUT : slbit := '0';
56
  signal R_LOCKED : slbit := '0';
57
 
58
begin
59
 
60
  proc_init : process
61
 
62
    -- currently frequency limits taken from Artix-7 speed grade -1
63
    constant f_vcomin_pll  : integer :=  800;
64
    constant f_vcomax_pll  : integer := 1600;
65
    constant f_pdmin_pll   : integer :=   19;
66
    constant f_pdmax_pll   : integer :=  450;
67
 
68
    constant f_vcomin_mmcm : integer :=  600;
69
    constant f_vcomax_mmcm : integer := 1200;
70
    constant f_pdmin_mmcm  : integer :=   10;
71
    constant f_pdmax_mmcm  : integer :=  450;
72
 
73
    variable t_vco : time := 0 ns;
74
    variable t_vcomin : time := 0 ns;
75
    variable t_vcomax : time := 0 ns;
76
    variable t_pd : time := 0 ns;
77
    variable t_pdmin : time := 0 ns;
78
    variable t_pdmax : time := 0 ns;
79
 
80
  begin
81
    -- validate generics
82
 
83
 
84
    if not (GEN_TYPE = "PLL" or GEN_TYPE = "MMCM") then
85
      assert false
86
        report "assert(GEN_TYPE='PLL' or GEN_TYPE='MMCM')"
87
        severity failure;
88
    end if;
89
 
90
    if VCO_DIVIDE/=1 or VCO_MULTIPLY/=1 or OUT_DIVIDE/=1 then
91
 
92
      if GEN_TYPE = "PLL" then
93
        -- check DIV/MULT parameter range
94
        if VCO_DIVIDE<1   or VCO_DIVIDE>56 or
95
          VCO_MULTIPLY<2 or VCO_MULTIPLY>64 or
96
          OUT_DIVIDE<1   or OUT_DIVIDE>128
97
        then
98
          assert false
99
            report
100
          "assert(VCO_DIVIDE in 1:56 VCO_MULTIPLY in 2:64 OUT_DIVIDE in 1:128)"
101
            severity failure;
102
        end if;
103
        -- setup VCO and PD range check boundaries
104
        t_vcomin := (1000 ns / f_vcomax_pll) - 1 ps;
105
        t_vcomax := (1000 ns / f_vcomin_pll) + 1 ps;
106
        t_pdmin  := (1000 ns / f_pdmax_pll) - 1 ps;
107
        t_pdmax  := (1000 ns / f_pdmin_pll) + 1 ps;
108
 
109
      end if; -- GEN_TYPE = "PLL"
110
 
111
      if GEN_TYPE = "MMCM" then
112
        -- check DIV/MULT parameter range
113
        if VCO_DIVIDE<1   or VCO_DIVIDE>106 or
114
           VCO_MULTIPLY<2 or VCO_MULTIPLY>64 or
115
           OUT_DIVIDE<1   or OUT_DIVIDE>128
116
        then
117
          assert false
118
            report
119
          "assert(VCO_DIVIDE in 1:106 VCO_MULTIPLY in 2:64 OUT_DIVIDE in 1:128)"
120
            severity failure;
121
        end if;
122
        -- setup VCO and PD range check boundaries
123
        t_vcomin := (1000 ns / f_vcomax_pll) - 1 ps;
124
        t_vcomax := (1000 ns / f_vcomin_pll) + 1 ps;
125
        t_pdmin  := (1000 ns / f_pdmax_pll) - 1 ps;
126
        t_pdmax  := (1000 ns / f_pdmin_pll) + 1 ps;
127
 
128
      end if; -- GEN_TYPE = "MMCM"
129
 
130
      -- now common check whether VCO and PD frequency is in range
131
      t_pd  := (1 ps * (1000.0*CLKIN_PERIOD)) * VCO_DIVIDE;
132
      t_vco := t_pd / VCO_MULTIPLY;
133
 
134
      if t_vco<t_vcomin or t_vco>t_vcomax then
135
        assert false
136
          report "assert(VCO frequency out of range)"
137
          severity failure;
138
      end if;
139
 
140
      if t_pd<t_pdmin or t_pd>t_pdmax then
141
        assert FALSE
142
          report "assert(PD frequency out of range)"
143
          severity failure;
144
      end if;
145
 
146
    end if;  -- one factor /= 1
147
 
148
    wait;
149
  end process proc_init;
150
 
151
  proc_clkin : process (CLKIN)
152
    variable t_lastclkin : time := 0 ns;
153
    variable t_lastperiod : time := 0 ns;
154
    variable t_period : time := 0 ns;
155
    variable nclkin : integer := 1;
156
  begin
157
 
158
    if CLKIN'event then
159
      if CLKIN = '1' then               -- if CLKIN rising edge
160
 
161
        if t_lastclkin > 0 ns then
162
          t_lastperiod := t_period;
163
          t_period := now - t_lastclkin;
164
          CLKOUT_PERIOD <= (t_period * VCO_DIVIDE * OUT_DIVIDE) / VCO_MULTIPLY;
165
          if t_lastperiod > 0 ns and abs(t_period-t_lastperiod) > 1 ps then
166
            report "s7_cmt_sp_sfs: CLKIN unstable" severity warning;
167
          end if;
168
        end if;
169
        t_lastclkin := now;
170
 
171
        if t_period > 0 ns then
172
          nclkin := nclkin - 1;
173
          if nclkin <= 0 then
174
            nclkin := VCO_DIVIDE * OUT_DIVIDE;
175
            CLK_DIVPULSE <= '1';
176
            R_LOCKED     <= '1';
177
          end if;
178
        end if;
179
 
180
      else                              -- if CLKIN falling edge
181
        CLK_DIVPULSE <= '0';
182
      end if;
183
    end if;
184
 
185
  end process proc_clkin;
186
 
187
  proc_clkout : process
188
    variable t_lastclkin : time := 0 ns;
189
    variable t_lastperiod : time := 0 ns;
190
    variable t_period : time := 0 ns;
191
    variable nclkin : integer := 1;
192
  begin
193
 
194
    loop
195
      wait until CLK_DIVPULSE = '1';
196
 
197
      for i in 1 to VCO_MULTIPLY loop
198
        R_CLKOUT <= '1';
199
        wait for CLKOUT_PERIOD/2;
200
        R_CLKOUT <= '0';
201
        if i /= VCO_MULTIPLY then
202
          wait for CLKOUT_PERIOD/2;
203
        end if;
204
      end loop;  -- i
205
 
206
    end loop;
207
 
208
  end process proc_clkout;
209
 
210
  CLKFX  <= R_CLKOUT;
211
  LOCKED <= R_LOCKED;
212
 
213
end sim;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.