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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [vlib/] [genlib/] [clkdivce.vhd] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 wfjm
-- $Id: clkdivce.vhd 807 2016-09-17 07:49:26Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 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
-- Module Name:    clkgen - syn
16
-- Description:    Generate usec and msec enable signals
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21 36 wfjm
-- Tool versions:  ise 8.2-14.7; viv 2014.4-2015.4; ghdl 0.18-0.33
22 2 wfjm
-- Revision History: 
23 37 wfjm
-- Date         Rev Version  Comment
24 13 wfjm
-- 2011-10-22   418   1.0.3  now numeric_std clean
25 2 wfjm
-- 2008-01-20   112   1.0.2  rename clkgen->clkdivce; remove SYS_CLK port
26
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
27
-- 2007-06-30    62   1.0    Initial version 
28
------------------------------------------------------------------------------
29 37 wfjm
-- Note: for test bench usage a copy of the clkdivce entity, with _tb
30
--       appended to the name, has been created in the /tb sub folder.
31
--       Ensure to update the copy when this file is changed !!
32 2 wfjm
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35 13 wfjm
use ieee.numeric_std.all;
36 2 wfjm
 
37
use work.slvtypes.all;
38
 
39
entity clkdivce is                      -- generate usec/msec ce pulses
40
  generic (
41
    CDUWIDTH : positive := 6;           -- usec clock divider width
42
    USECDIV : positive :=  50;          -- divider ratio for usec pulse
43
    MSECDIV : positive := 1000);        -- divider ratio for msec pulse
44
  port (
45
    CLK     : in slbit;                 -- input clock
46
    CE_USEC : out slbit;                -- usec pulse
47
    CE_MSEC : out slbit                 -- msec pulse
48
  );
49
end clkdivce;
50
 
51
 
52
architecture syn of clkdivce is
53
 
54
  type regs_type is record
55
    ucnt : slv(CDUWIDTH-1 downto 0);    -- usec clock divider counter
56
    mcnt : slv10;                       -- msec clock divider counter
57
    usec : slbit;                       -- usec pulse
58
    msec : slbit;                       -- msec pulse
59
  end record regs_type;
60
 
61
  constant regs_init : regs_type := (
62 13 wfjm
    slv(to_unsigned(USECDIV-1,CDUWIDTH)),
63
    slv(to_unsigned(MSECDIV-1,10)),
64 2 wfjm
    '0','0'
65
  );
66
 
67
  signal R_REGS : regs_type := regs_init;  -- state registers
68
  signal N_REGS : regs_type := regs_init;  -- next value state regs
69
 
70
begin
71
 
72
  assert USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024
73
    report "assert(USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024): " &
74
           "USECDIV too large for given CDUWIDTH or MSECDIV>1024"
75 36 wfjm
    severity failure;
76 2 wfjm
 
77
  proc_regs: process (CLK)
78
  begin
79
 
80 13 wfjm
    if rising_edge(CLK) then
81 2 wfjm
      R_REGS <= N_REGS;
82
    end if;
83
 
84
  end process proc_regs;
85
 
86
  proc_next: process (R_REGS)
87
 
88
    variable r : regs_type := regs_init;
89
    variable n : regs_type := regs_init;
90
 
91
  begin
92
 
93
    r := R_REGS;
94
    n := R_REGS;
95
 
96
    n.usec := '0';
97
    n.msec := '0';
98
 
99 13 wfjm
    n.ucnt := slv(unsigned(r.ucnt) - 1);
100 2 wfjm
    if unsigned(r.ucnt) = 0 then
101
      n.usec := '1';
102 13 wfjm
      n.ucnt := slv(to_unsigned(USECDIV-1,CDUWIDTH));
103
      n.mcnt := slv(unsigned(r.mcnt) - 1);
104 2 wfjm
      if unsigned(r.mcnt) = 0 then
105
        n.msec := '1';
106 13 wfjm
        n.mcnt := slv(to_unsigned(MSECDIV-1,10));
107 2 wfjm
      end if;
108
    end if;
109
 
110
    N_REGS <= n;
111
 
112
    CE_USEC <= r.usec;
113
    CE_MSEC <= r.msec;
114
 
115
  end process proc_next;
116
 
117
 
118
end syn;

powered by: WebSVN 2.1.0

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