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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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