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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [vlib/] [xlib/] [s6_cmt_sfs_gsim.vhd] - Blame information for rev 29

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

Line No. Rev Author Line
1 29 wfjm
-- $Id: s6_cmt_sfs_gsim.vhd 649 2015-02-21 21:10:16Z mueller $
2 22 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:    s6_cmt_sfs - sim
16
-- Description:    Spartan-6 CMT for simple frequency synthesis
17
--                 simple vhdl model, without Xilinx UNISIM primitives
18
--
19
-- Dependencies:   -
20
-- Test bench:     -
21
-- Target Devices: generic Spartan-6
22 29 wfjm
-- Tool versions:  xst 14.5-14.7; ghdl 0.29-0.31
23 22 wfjm
--
24
-- Revision History: 
25
-- Date         Rev Version  Comment
26
-- 2013-10-06   538   1.0    Initial version (derived from s7_cmt_sfs_gsim)
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
 
32
use work.slvtypes.all;
33
 
34
entity s6_cmt_sfs is                    -- Spartan-6 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 s6_cmt_sfs;
49
 
50
 
51
architecture sim of s6_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 Spartan-6 speed grade -2
63
    constant f_vcomin_pll  : integer :=  400;
64
    constant f_vcomax_pll  : integer := 1000;
65
    constant f_pdmin_pll   : integer :=   19;
66
    constant f_pdmax_pll   : integer :=  375;
67
 
68
    variable t_vco : time := 0 ns;
69
    variable t_vcomin : time := 0 ns;
70
    variable t_vcomax : time := 0 ns;
71
    variable t_pd : time := 0 ns;
72
    variable t_pdmin : time := 0 ns;
73
    variable t_pdmax : time := 0 ns;
74
 
75
  begin
76
    -- validate generics
77
 
78
 
79
    if not (GEN_TYPE = "PLL" or GEN_TYPE = "DCM") then
80
      assert false
81
        report "assert(GEN_TYPE='PLL' or GEN_TYPE='DCM')"
82
        severity failure;
83
    end if;
84
 
85
    if VCO_DIVIDE/=1 or VCO_MULTIPLY/=1 or OUT_DIVIDE/=1 then
86
 
87
      if GEN_TYPE = "PLL" then
88
        -- check DIV/MULT parameter range
89
        if VCO_DIVIDE<1   or VCO_DIVIDE>52 or
90
           VCO_MULTIPLY<1 or VCO_MULTIPLY>64 or
91
           OUT_DIVIDE<1   or OUT_DIVIDE>128
92
        then
93
          assert false
94
            report
95
          "assert(VCO_DIVIDE in 1:52 VCO_MULTIPLY in 1:64 OUT_DIVIDE in 1:128)"
96
            severity failure;
97
        end if;
98
        -- setup VCO and PD range check boundaries
99
        t_vcomin := (1000 ns / f_vcomax_pll) - 1 ps;
100
        t_vcomax := (1000 ns / f_vcomin_pll) + 1 ps;
101
        t_pdmin  := (1000 ns / f_pdmax_pll) - 1 ps;
102
        t_pdmax  := (1000 ns / f_pdmin_pll) + 1 ps;
103
 
104
        -- now check whether VCO and PD frequency is in range
105
        t_pd  := (1 ps * (1000.0*CLKIN_PERIOD)) * VCO_DIVIDE;
106
        t_vco := t_pd / VCO_MULTIPLY;
107
 
108
        if t_vco<t_vcomin or t_vco>t_vcomax then
109
          assert false
110
            report "assert(VCO frequency out of range)"
111
            severity failure;
112
        end if;
113
 
114
        if t_pd<t_pdmin or t_pd>t_pdmax then
115
          assert FALSE
116
            report "assert(PD frequency out of range)"
117
            severity failure;
118
        end if;
119
 
120
    end if; -- GEN_TYPE = "PLL"
121
 
122
      if GEN_TYPE = "DCM" then
123
        -- check DIV/MULT parameter range
124
        if VCO_DIVIDE<1   or VCO_DIVIDE>32 or
125
           VCO_MULTIPLY<2 or VCO_MULTIPLY>32 or
126
           OUT_DIVIDE/=1
127
        then
128
          assert false
129
            report
130
          "assert(VCO_DIVIDE in 1:32 VCO_MULTIPLY in 2:32 OUT_DIVIDE=1)"
131
            severity failure;
132
        end if;
133
      end if; -- GEN_TYPE = "MMCM"
134
 
135
    end if;  -- one factor /= 1
136
 
137
    wait;
138
  end process proc_init;
139
 
140
  proc_clkin : process (CLKIN)
141
    variable t_lastclkin : time := 0 ns;
142
    variable t_lastperiod : time := 0 ns;
143
    variable t_period : time := 0 ns;
144
    variable nclkin : integer := 1;
145
  begin
146
 
147
    if CLKIN'event then
148
      if CLKIN = '1' then               -- if CLKIN rising edge
149
 
150
        if t_lastclkin > 0 ns then
151
          t_lastperiod := t_period;
152
          t_period := now - t_lastclkin;
153
          CLKOUT_PERIOD <= (t_period * VCO_DIVIDE * OUT_DIVIDE) / VCO_MULTIPLY;
154
          if t_lastperiod > 0 ns and abs(t_period-t_lastperiod) > 1 ps then
155
            report "s6_cmt_sp_sfs: CLKIN unstable" severity warning;
156
          end if;
157
        end if;
158
        t_lastclkin := now;
159
 
160
        if t_period > 0 ns then
161
          nclkin := nclkin - 1;
162
          if nclkin <= 0 then
163
            nclkin := VCO_DIVIDE * OUT_DIVIDE;
164
            CLK_DIVPULSE <= '1';
165
            R_LOCKED     <= '1';
166
          end if;
167
        end if;
168
 
169
      else                              -- if CLKIN falling edge
170
        CLK_DIVPULSE <= '0';
171
      end if;
172
    end if;
173
 
174
  end process proc_clkin;
175
 
176
  proc_clkout : process
177
    variable t_lastclkin : time := 0 ns;
178
    variable t_lastperiod : time := 0 ns;
179
    variable t_period : time := 0 ns;
180
    variable nclkin : integer := 1;
181
  begin
182
 
183
    loop
184
      wait until CLK_DIVPULSE = '1';
185
 
186
      for i in 1 to VCO_MULTIPLY loop
187
        R_CLKOUT <= '1';
188
        wait for CLKOUT_PERIOD/2;
189
        R_CLKOUT <= '0';
190
        if i /= VCO_MULTIPLY then
191
          wait for CLKOUT_PERIOD/2;
192
        end if;
193
      end loop;  -- i
194
 
195
    end loop;
196
 
197
  end process proc_clkout;
198
 
199
  CLKFX  <= R_CLKOUT;
200
  LOCKED <= R_LOCKED;
201
 
202
end sim;

powered by: WebSVN 2.1.0

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