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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [vlib/] [xlib/] [dcm_sfs_gsim.vhd] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 wfjm
-- $Id: dcm_sfs_gsim.vhd 426 2011-11-18 18:14:08Z mueller $
2 8 wfjm
--
3 13 wfjm
-- Copyright 2010-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 8 wfjm
--
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 13 wfjm
-- Module Name:    dcm_sfs - sim
16
-- Description:    DCM for simple frequency synthesis
17 8 wfjm
--                 simple vhdl model, without Xilinx UNISIM primitives
18
--
19
-- Dependencies:   -
20
-- Test bench:     -
21
-- Target Devices: generic Spartan-3A,-3E
22 13 wfjm
-- Tool versions:  xst 12.1, 13.1; ghdl 0.29
23 8 wfjm
--
24
-- Revision History: 
25
-- Date         Rev Version  Comment
26 13 wfjm
-- 2011-11-17   426   1.0.1  rename dcm_sp_sfs -> dcm_sfs
27 8 wfjm
-- 2010-11-12   338   1.0    Initial version 
28
------------------------------------------------------------------------------
29
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
 
33
use work.slvtypes.all;
34
 
35 13 wfjm
entity dcm_sfs is                       -- DCM for simple frequency synthesis
36 8 wfjm
  generic (
37
    CLKFX_DIVIDE : positive := 1;       -- FX clock divide   (1-32)
38
    CLKFX_MULTIPLY : positive := 1;     -- FX clock multiply (2-32) (1->no DCM)
39
    CLKIN_PERIOD : real := 20.0);       -- CLKIN period (def is 20.0 ns)
40
  port (
41
    CLKIN : in slbit;                   -- clock input
42
    CLKFX : out slbit;                  -- clock output (synthesized freq.) 
43
    LOCKED : out slbit                  -- dcm locked
44
  );
45 13 wfjm
end dcm_sfs;
46 8 wfjm
 
47
 
48 13 wfjm
architecture sim of dcm_sfs is
49 8 wfjm
 
50
  signal CLK_DIVPULSE : slbit := '0';
51
  signal CLKOUT_PERIOD : time := 0 ns;
52
  signal R_CLKOUT : slbit := '0';
53
  signal R_LOCKED : slbit := '0';
54
 
55
begin
56
 
57
  proc_clkin : process (CLKIN)
58
    variable t_lastclkin : time := 0 ns;
59
    variable t_lastperiod : time := 0 ns;
60
    variable t_period : time := 0 ns;
61
    variable nclkin : integer := 1;
62
  begin
63
 
64
    if CLKIN'event then
65
      if CLKIN = '1' then               -- if CLKIN rising edge
66
 
67
        if t_lastclkin > 0 ns then
68
          t_lastperiod := t_period;
69
          t_period := now - t_lastclkin;
70
          CLKOUT_PERIOD <= (t_period * CLKFX_DIVIDE) / CLKFX_MULTIPLY;
71
          if t_lastperiod > 0 ns and abs(t_period-t_lastperiod) > 1 ps then
72
            report "dcm_sp_sfs: CLKIN unstable" severity warning;
73
          end if;
74
        end if;
75
        t_lastclkin := now;
76
 
77
        if t_period > 0 ns then
78
          nclkin := nclkin - 1;
79
          if nclkin <= 0 then
80
            nclkin := CLKFX_DIVIDE;
81
            CLK_DIVPULSE <= '1';
82
            R_LOCKED     <= '1';
83
          end if;
84
        end if;
85
 
86
      else                              -- if CLKIN falling edge
87
        CLK_DIVPULSE <= '0';
88
      end if;
89
    end if;
90
 
91
  end process proc_clkin;
92
 
93
  proc_clkout : process
94
    variable t_lastclkin : time := 0 ns;
95
    variable t_lastperiod : time := 0 ns;
96
    variable t_period : time := 0 ns;
97
    variable nclkin : integer := 1;
98
  begin
99
 
100
    loop
101
      wait until CLK_DIVPULSE = '1';
102
 
103
      for i in 1 to CLKFX_MULTIPLY loop
104
        R_CLKOUT <= '1';
105
        wait for CLKOUT_PERIOD/2;
106
        R_CLKOUT <= '0';
107
        if i /= CLKFX_MULTIPLY then
108
          wait for CLKOUT_PERIOD/2;
109
        end if;
110
      end loop;  -- i
111
 
112
    end loop;
113
 
114
  end process proc_clkout;
115
 
116
  CLKFX  <= R_CLKOUT;
117
  LOCKED <= R_LOCKED;
118
 
119
end sim;

powered by: WebSVN 2.1.0

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