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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 wfjm
-- $Id: gray_cnt_n.vhd 418 2011-10-23 20:11:40Z mueller $
2
--
3
-- Copyright 2007- 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:    gray_cnt_n - syn
16
-- Description:    Genric width Gray code counter
17
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_debounce_gen
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25
22
-- Revision History: 
23
-- Date         Rev Version    Comment
24
-- 2007-12-26   106   1.0      Initial version 
25
--
26
-- Some synthesis results:
27
-- - 2007-12-27 ise 8.2.03 for xc3s1000-ft256-4:
28
--   DWIDTH  LUT Flop   clock(xst est.)
29
--        4    6    5   305MHz/ 3.28ns
30
--        5    8    6   286MHz/ 2.85ns
31
--        8   13    9   234MHz/ 4.26ns
32
--       16   56   17   149MHz/ 6.67ns
33
--       32   95   33   161MHz/ 6.19ns
34
--       64  188   68   126MHz/ 7.90ns
35
------------------------------------------------------------------------------
36
 
37
library ieee;
38
use ieee.std_logic_1164.all;
39
 
40
use work.slvtypes.all;
41
use work.genlib.all;
42
 
43
entity gray_cnt_n is                    -- n bit gray code counter
44
  generic (
45
    DWIDTH : positive := 8);            -- data width
46
  port (
47
    CLK : in slbit;                     -- clock
48
    RESET : in slbit := '0';            -- reset
49
    CE : in slbit := '1';               -- count enable
50
    DATA : out slv(DWIDTH-1 downto 0)   -- data out
51
  );
52
end entity gray_cnt_n;
53
 
54
 
55
architecture syn of gray_cnt_n is
56
 
57
  signal R_AUX : slbit := '1';
58
  signal R_DATA : slv(DWIDTH-1 downto 0) := (others=>'0');
59
  signal N_DATA : slv(DWIDTH-1 downto 0) := (others=>'0');
60
 
61
begin
62
 
63
  assert DWIDTH>=3
64
    report "assert(DWIDTH>=3): only 3 bit or larger supported"
65
    severity failure;
66
 
67
  proc_regs: process (CLK)
68
  begin
69
 
70
    if rising_edge(CLK) then
71
      if RESET = '1' then
72
        R_AUX  <= '1';
73
        R_DATA <= (others=>'0');
74
      elsif CE = '1' then
75
        R_AUX  <= not R_AUX;
76
        R_DATA <= N_DATA;
77
      end if;
78
    end if;
79
  end process proc_regs;
80
 
81
  proc_next: process (R_AUX, R_DATA)
82
    variable r : slv(DWIDTH-1 downto 0) := (others=>'0');
83
    variable n : slv(DWIDTH-1 downto 0) := (others=>'0');
84
    variable s : slbit := '0';
85
  begin
86
 
87
    r := R_DATA;
88
    n := R_DATA;
89
    s := '1';
90
 
91
    if R_AUX = '1' then
92
      n(0) := not r(0);
93
    else
94
      for i in 1 to DWIDTH-2 loop
95
        if s='1' and r(i-1)='1' then
96
          n(i) := not r(i);
97
        end if;
98
        s := s and not r(i-1);
99
      end loop;
100
      if s = '1' then
101
        n(DWIDTH-1) := r(DWIDTH-2);
102
      end if;
103
    end if;
104
 
105
    N_DATA <= n;
106
 
107
  end process proc_next;
108
 
109
  DATA <= R_DATA;
110
 
111
end syn;
112
 

powered by: WebSVN 2.1.0

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