w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
debounce_gen.vhd
Go to the documentation of this file.
1-- $Id: debounce_gen.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: debounce_gen - syn
7-- Description: Generic signal debouncer
8--
9-- Dependencies: -
10-- Test bench: tb/tb_debounce_gen
11-- Target Devices: generic
12-- Tool versions: ise 8.2-14.7; viv 2014.4-2015.4; ghdl 0.18-0.33
13-- Revision History:
14-- Date Rev Version Comment
15-- 2011-10-22 418 1.0.3 now numeric_std clean
16-- 2007-12-26 105 1.0.2 add default for RESET
17-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned
18-- 2007-06-29 61 1.0 Initial version
19------------------------------------------------------------------------------
20
21library ieee;
22use ieee.std_logic_1164.all;
23use ieee.numeric_std.all;
24
25use work.slvtypes.all;
26
27entity debounce_gen is -- debounce, generic vector
28 generic (
29 CWIDTH : positive := 2; -- clock interval counter width
30 CEDIV : positive := 3; -- clock interval divider
31 DWIDTH : positive := 8); -- data width
32 port (
33 CLK : in slbit; -- clock
34 RESET : in slbit := '0'; -- reset
35 CE_INT : in slbit; -- clock interval enable (usec or msec)
36 DI : in slv(DWIDTH-1 downto 0); -- data in
37 DO : out slv(DWIDTH-1 downto 0) -- data out
38 );
39end entity debounce_gen;
40
41
42architecture syn of debounce_gen is
43
44 constant cntzero : slv(CWIDTH-1 downto 0) := (others=>'0');
45 constant datazero : slv(dWIDTH-1 downto 0) := (others=>'0');
46
47 type regs_type is record
48 cecnt : slv(CWIDTH-1 downto 0); -- clock interval counter
49 dref : slv(DWIDTH-1 downto 0); -- data reference
50 dchange : slv(DWIDTH-1 downto 0); -- data change flag
51 dout : slv(DWIDTH-1 downto 0); -- data output
52 end record regs_type;
53
54 constant regs_init : regs_type := (
55 cntzero,
59 );
60
61 signal R_REGS : regs_type := regs_init; -- state registers
62 signal N_REGS : regs_type := regs_init; -- next value state regs
63
64begin
65
66 assert CEDIV<=2**CWIDTH report "assert(CEDIV<=2**CWIDTH)" severity failure;
67
68 proc_regs: process (CLK)
69 begin
70
71 if rising_edge(CLK) then
72 if RESET = '1' then
73 R_REGS.cecnt <= cntzero;
74 R_REGS.dref <= DI;
75 R_REGS.dchange <= datazero;
76 R_REGS.dout <= DI;
77 else
78 R_REGS <= N_REGS;
79 end if;
80 end if;
81
82 end process proc_regs;
83
84 proc_next: process (R_REGS, CE_INT, DI)
85
86 variable r : regs_type := regs_init;
87 variable n : regs_type := regs_init;
88
89 begin
90
91 r := R_REGS;
92 n := R_REGS;
93
94 for i in DI'range loop
95 if DI(i) /= r.dref(i) then
96 n.dchange(i) := '1';
97 end if;
98 end loop;
99
100 if CE_INT = '1' then
101 if unsigned(r.cecnt) = 0 then
102 n.cecnt := slv(to_unsigned(CEDIV-1,CWIDTH));
103 n.dref := DI;
104 n.dchange := datazero;
105 for i in DI'range loop
106 if r.dchange(i) = '0' then
107 n.dout(i) := r.dref(i);
108 end if;
109 end loop;
110
111 else
112 n.cecnt := slv(unsigned(r.cecnt) - 1);
113 end if;
114 end if;
115
116 N_REGS <= n;
117
118 DO <= r.dout;
119
120 end process proc_next;
121
122
123end syn;
124
regs_type :=( cntzero, datazero, datazero, datazero) regs_init
regs_type := regs_init N_REGS
slv( dWIDTH- 1 downto 0) :=( others => '0') datazero
slv( CWIDTH- 1 downto 0) :=( others => '0') cntzero
regs_type := regs_init R_REGS
DWIDTH positive := 8
in CE_INT slbit
out DO slv( DWIDTH- 1 downto 0)
in DI slv( DWIDTH- 1 downto 0)
CWIDTH positive := 2
in CLK slbit
CEDIV positive := 3
in RESET slbit := '0'
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector slv
Definition: slvtypes.vhd:31