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 37

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

Line No. Rev Author Line
1 37 wfjm
-- $Id: s6_cmt_sfs_gsim.vhd 799 2016-08-21 09:20:19Z 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 37 wfjm
-- Tool versions:  xst 14.5-14.7; ghdl 0.29-0.33
23 22 wfjm
--
24
-- Revision History: 
25
-- Date         Rev Version  Comment
26 37 wfjm
-- 2016-08-18   799   1.0.1  remove 'assert false' from report statements
27 22 wfjm
-- 2013-10-06   538   1.0    Initial version (derived from s7_cmt_sfs_gsim)
28
------------------------------------------------------------------------------
29
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
 
33
use work.slvtypes.all;
34
 
35
entity s6_cmt_sfs is                    -- Spartan-6 CMT for simple freq. synth.
36
  generic (
37
    VCO_DIVIDE : positive := 1;         -- vco clock divide
38
    VCO_MULTIPLY : positive := 1;       -- vco clock multiply 
39
    OUT_DIVIDE : positive := 1;         -- output divide
40
    CLKIN_PERIOD : real := 10.0;        -- CLKIN period (def is 10.0 ns)
41
    CLKIN_JITTER : real := 0.01;        -- CLKIN jitter (def is 10 ps)
42
    STARTUP_WAIT : boolean := false;    -- hold FPGA startup till LOCKED
43
    GEN_TYPE : string := "PLL");        -- PLL or MMCM
44
  port (
45
    CLKIN : in slbit;                   -- clock input
46
    CLKFX : out slbit;                  -- clock output (synthesized freq.) 
47
    LOCKED : out slbit                  -- pll/mmcm locked
48
  );
49
end s6_cmt_sfs;
50
 
51
 
52
architecture sim of s6_cmt_sfs is
53
 
54
  signal CLK_DIVPULSE : slbit := '0';
55 37 wfjm
  signal CLKOUT_PERIOD : Delay_length := 0 ns;
56 22 wfjm
  signal R_CLKOUT : slbit := '0';
57
  signal R_LOCKED : slbit := '0';
58
 
59
begin
60
 
61
  proc_init : process
62
 
63
    -- currently frequency limits taken from Spartan-6 speed grade -2
64
    constant f_vcomin_pll  : integer :=  400;
65
    constant f_vcomax_pll  : integer := 1000;
66
    constant f_pdmin_pll   : integer :=   19;
67
    constant f_pdmax_pll   : integer :=  375;
68
 
69 37 wfjm
    variable t_vco : Delay_length := 0 ns;
70
    variable t_vcomin : Delay_length := 0 ns;
71
    variable t_vcomax : Delay_length := 0 ns;
72
    variable t_pd : Delay_length := 0 ns;
73
    variable t_pdmin : Delay_length := 0 ns;
74
    variable t_pdmax : Delay_length := 0 ns;
75 22 wfjm
 
76
  begin
77
    -- validate generics
78
 
79
 
80
    if not (GEN_TYPE = "PLL" or GEN_TYPE = "DCM") then
81 37 wfjm
      report "assert(GEN_TYPE='PLL' or GEN_TYPE='DCM')"
82 22 wfjm
        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 37 wfjm
          report
94 22 wfjm
          "assert(VCO_DIVIDE in 1:52 VCO_MULTIPLY in 1:64 OUT_DIVIDE in 1:128)"
95
            severity failure;
96
        end if;
97
        -- setup VCO and PD range check boundaries
98
        t_vcomin := (1000 ns / f_vcomax_pll) - 1 ps;
99
        t_vcomax := (1000 ns / f_vcomin_pll) + 1 ps;
100
        t_pdmin  := (1000 ns / f_pdmax_pll) - 1 ps;
101
        t_pdmax  := (1000 ns / f_pdmin_pll) + 1 ps;
102
 
103
        -- now check whether VCO and PD frequency is in range
104
        t_pd  := (1 ps * (1000.0*CLKIN_PERIOD)) * VCO_DIVIDE;
105
        t_vco := t_pd / VCO_MULTIPLY;
106
 
107
        if t_vco<t_vcomin or t_vco>t_vcomax then
108 37 wfjm
          report "assert(VCO frequency out of range)"
109 22 wfjm
            severity failure;
110
        end if;
111
 
112
        if t_pd<t_pdmin or t_pd>t_pdmax then
113 37 wfjm
          report "assert(PD frequency out of range)"
114 22 wfjm
            severity failure;
115
        end if;
116
 
117
    end if; -- GEN_TYPE = "PLL"
118
 
119
      if GEN_TYPE = "DCM" then
120
        -- check DIV/MULT parameter range
121
        if VCO_DIVIDE<1   or VCO_DIVIDE>32 or
122
           VCO_MULTIPLY<2 or VCO_MULTIPLY>32 or
123
           OUT_DIVIDE/=1
124
        then
125 37 wfjm
          report
126 22 wfjm
          "assert(VCO_DIVIDE in 1:32 VCO_MULTIPLY in 2:32 OUT_DIVIDE=1)"
127
            severity failure;
128
        end if;
129
      end if; -- GEN_TYPE = "MMCM"
130
 
131
    end if;  -- one factor /= 1
132
 
133
    wait;
134
  end process proc_init;
135
 
136
  proc_clkin : process (CLKIN)
137
    variable t_lastclkin : time := 0 ns;
138 37 wfjm
    variable t_lastperiod : Delay_length := 0 ns;
139
    variable t_period : Delay_length := 0 ns;
140 22 wfjm
    variable nclkin : integer := 1;
141
  begin
142
 
143
    if CLKIN'event then
144
      if CLKIN = '1' then               -- if CLKIN rising edge
145
 
146
        if t_lastclkin > 0 ns then
147
          t_lastperiod := t_period;
148
          t_period := now - t_lastclkin;
149
          CLKOUT_PERIOD <= (t_period * VCO_DIVIDE * OUT_DIVIDE) / VCO_MULTIPLY;
150
          if t_lastperiod > 0 ns and abs(t_period-t_lastperiod) > 1 ps then
151
            report "s6_cmt_sp_sfs: CLKIN unstable" severity warning;
152
          end if;
153
        end if;
154
        t_lastclkin := now;
155
 
156
        if t_period > 0 ns then
157
          nclkin := nclkin - 1;
158
          if nclkin <= 0 then
159
            nclkin := VCO_DIVIDE * OUT_DIVIDE;
160
            CLK_DIVPULSE <= '1';
161
            R_LOCKED     <= '1';
162
          end if;
163
        end if;
164
 
165
      else                              -- if CLKIN falling edge
166
        CLK_DIVPULSE <= '0';
167
      end if;
168
    end if;
169
 
170
  end process proc_clkin;
171
 
172
  proc_clkout : process
173
    variable t_lastclkin : time := 0 ns;
174 37 wfjm
    variable t_lastperiod : Delay_length := 0 ns;
175
    variable t_period : Delay_length := 0 ns;
176 22 wfjm
    variable nclkin : integer := 1;
177
  begin
178
 
179
    loop
180
      wait until CLK_DIVPULSE = '1';
181
 
182
      for i in 1 to VCO_MULTIPLY loop
183
        R_CLKOUT <= '1';
184
        wait for CLKOUT_PERIOD/2;
185
        R_CLKOUT <= '0';
186
        if i /= VCO_MULTIPLY then
187
          wait for CLKOUT_PERIOD/2;
188
        end if;
189
      end loop;  -- i
190
 
191
    end loop;
192
 
193
  end process proc_clkout;
194
 
195
  CLKFX  <= R_CLKOUT;
196
  LOCKED <= R_LOCKED;
197
 
198
end sim;

powered by: WebSVN 2.1.0

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