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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 wfjm
-- $Id: debounce_gen.vhd 418 2011-10-23 20:11:40Z 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:    debounce_gen - syn
16
-- Description:    Generic signal debouncer
17
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_debounce_gen
20
-- Target Devices: generic
21 13 wfjm
-- Tool versions:  xst 8.2, 9.1, 9.2, 13.1; ghdl 0.18-0.29
22 2 wfjm
-- Revision History: 
23
-- Date         Rev Version  Comment
24 13 wfjm
-- 2011-10-22   418   1.0.3  now numeric_std clean
25 2 wfjm
-- 2007-12-26   105   1.0.2  add default for RESET
26
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
27
-- 2007-06-29    61   1.0    Initial version 
28
------------------------------------------------------------------------------
29
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32 13 wfjm
use ieee.numeric_std.all;
33 2 wfjm
 
34
use work.slvtypes.all;
35
 
36
entity debounce_gen is                  -- debounce, generic vector
37
  generic (
38
    CWIDTH : positive := 2;             -- clock interval counter width
39
    CEDIV : positive := 3;              -- clock interval divider
40
    DWIDTH : positive := 8);            -- data width
41
  port (
42
    CLK : in slbit;                     -- clock
43
    RESET : in slbit := '0';            -- reset
44
    CE_INT : in slbit;                  -- clock interval enable (usec or msec)
45
    DI : in slv(DWIDTH-1 downto 0);     -- data in
46
    DO : out slv(DWIDTH-1 downto 0)     -- data out
47
  );
48
end entity debounce_gen;
49
 
50
 
51
architecture syn of debounce_gen is
52
 
53
  constant cntzero : slv(CWIDTH-1 downto 0) := (others=>'0');
54
  constant datazero : slv(dWIDTH-1 downto 0) := (others=>'0');
55
 
56
  type regs_type is record
57
    cecnt : slv(CWIDTH-1 downto 0);     -- clock interval counter
58
    dref : slv(DWIDTH-1 downto 0);      -- data reference
59
    dchange : slv(DWIDTH-1 downto 0);   -- data change flag
60
    dout : slv(DWIDTH-1 downto 0);      -- data output
61
  end record regs_type;
62
 
63
  constant regs_init : regs_type := (
64
    cntzero,
65
    datazero,
66
    datazero,
67
    datazero
68
  );
69
 
70
  signal R_REGS : regs_type := regs_init;  -- state registers
71
  signal N_REGS : regs_type := regs_init;  -- next value state regs
72
 
73
begin
74
 
75
  assert CEDIV<=2**CWIDTH report "assert(CEDIV<=2**CWIDTH)" severity failure;
76
 
77
  proc_regs: process (CLK)
78
  begin
79
 
80 13 wfjm
    if rising_edge(CLK) then
81 2 wfjm
      if RESET = '1' then
82
        R_REGS.cecnt <= cntzero;
83
        R_REGS.dref  <= DI;
84
        R_REGS.dchange <= datazero;
85
        R_REGS.dout  <= DI;
86
      else
87
        R_REGS <= N_REGS;
88
      end if;
89
    end if;
90
 
91
  end process proc_regs;
92
 
93
  proc_next: process (R_REGS, CE_INT, DI)
94
 
95
    variable r : regs_type := regs_init;
96
    variable n : regs_type := regs_init;
97
 
98
  begin
99
 
100
    r := R_REGS;
101
    n := R_REGS;
102
 
103
    for i in DI'range loop
104
      if DI(i) /= r.dref(i) then
105
        n.dchange(i) := '1';
106
      end if;
107
    end loop;
108
 
109
    if CE_INT = '1' then
110
      if unsigned(r.cecnt) = 0 then
111 13 wfjm
        n.cecnt := slv(to_unsigned(CEDIV-1,CWIDTH));
112 2 wfjm
        n.dref  := DI;
113
        n.dchange := datazero;
114
        for i in DI'range loop
115
          if r.dchange(i) = '0' then
116
            n.dout(i) := r.dref(i);
117
          end if;
118
        end loop;
119
 
120
      else
121 13 wfjm
        n.cecnt := slv(unsigned(r.cecnt) - 1);
122 2 wfjm
      end if;
123
    end if;
124
 
125
    N_REGS <= n;
126
 
127
    DO <= r.dout;
128
 
129
  end process proc_next;
130
 
131
 
132
end syn;
133
 

powered by: WebSVN 2.1.0

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