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

Subversion Repositories spi_master_slave

[/] [spi_master_slave/] [trunk/] [syn/] [grp_debouncer.vhd] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 jdoin
-----------------------------------------------------------------------------------------------------------------------
2
-- Author:          Jonny Doin, jdoin@opencores.org
3
-- 
4
-- Create Date:     09:56:30 07/06/2011  
5
-- Module Name:     grp_debouncer - RTL
6
-- Project Name:    generic functions
7
-- Target Devices:  Spartan-6
8
-- Tool versions:   ISE 13.1
9
-- Description: 
10
--
11
--      This block is a generic multiple input debouncing circuit.
12
--      It handles multiple inputs, like mechanical switch inputs, and outputs a debounced, stable registered version of the inputs.
13
--      A 'new_data' one-cycle strobe is also available, to sync downstream logic.
14
--
15
--      CONCEPTUAL CIRCUIT
16
--      ==================
17
--                                                                                                                          
18
--                                           W                                                                               
19
--                          /----------------/----------------\                                                                             
20
--                          |                                 |                                                             
21
--                          |                                 |                                                                   
22
--                          |        ______        ______     |         _____                                               
23
--                          |    W   |    |   W    |fdr |  W  |    W    |cmp \                                                 
24
--                          \----/---| +1 |---/----|    |--/--+----/----|     \                                                
25
--                                   |    |        |    |               |      \                                               
26
--                                   ------        |    |               \       |                                              
27
--                                                 |    |                |   =  |-----\                                           
28
--                                                 |> R |               /       |     |                                           
29
--                                                 ---+--               |      /      |                                           
30
--                                                    |       CNT_VAL---|     /       |                                           
31
--                                                    |                 |____/        |                                           
32
--                                                    |                               |                                           
33
--                                                    \------------\                  |                                           
34
--                                                                 |                  |                                           
35
--                                      N    ____                  |                  |                                           
36
--                              /-------/---))   \      ____       |                  |                                              
37
--                              |           ))XOR |-----)   \      |                  |                                           
38
--                              |    /------))___/      )OR  |-----/                  |                                           
39
--                              |    |              /---)___/                         |                                           
40
--                              |    |              |                                 |                                        
41
--                              |    |              \----------\                      |                                           
42
--                              |    |        N                |                      |                                           
43
--                              |    \--------/-----------\    +----------------------+-----------\                                              
44
--                              |                         |    |                                  |                               
45
--                              \---\                     |    |                                  |                               
46
--                     ______       |        ______       |    |   ______                         |                                                                                          
47
--                     | fd |       |        | fd |       |    |   |fde |                         |                                                                                          
48
--   [data_i]----/-----|    |---/---+---/----|    |---/---+----)---|    |---/---+---/-------------)----------------------[data_o]                                                            
49
--               N     |    |   N       N    |    |   N   |    |   |    |   N   |   N             |                                                                                          
50
--                     |    |                |    |       |    \---|CE  |       |                 |                                                                                          
51
--                     |    |                |    |       |        |    |       |                 |                                                                                          
52
--   [clk_i]---->      |>   |                |>   |       |        |>   |       |                 |     ____                                                                                        
53
--                     ------                ------       |        ------       |    N     ____   \-----|   \                                                                                                
54
--                                                        |                     \----/----))   \        |AND |-----------[strb_o]                               
55
--                                                        |                               ))XOR |-------|___/                                                    
56
--                                                        \--------------------------/----))___/                                     
57
--                                                                                   N                                               
58
--                                                                                                                          
59
--                                                                                                                          
60
--      PIPELINE LOGIC
61
--      ==============
62
--
63
--      This debouncer circuit detects edges in an input signal, and waits the signal to stabilize for the designated time 
64
--      before transferring the stable signal to the registered output. 
65
--      A one-clock-cyle strobe is pulsed at the output to signalize a new data available.
66
--      The core clock should be the system clock, to optimize use of global clock resources.
67
--
68
--      GROUP DEBOUNCING
69
--      ================
70
--
71
--      A change in state in any bit in the input word causes reload of the delay counter, and the output word is updated only 
72
--      when all bits are stable for the specified period. Therefore, the grouping of signals and delay selection should match
73
--      behaviour of the selected signals.
74
--
75
--      RESOURCES USED
76
--      ==============
77
--
78
--      The number of registers inferred is: 3*N + (LOG(CNT_VAL)/LOG(2)) registers.
79
--      The number of LUTs inferred is roughly: ((4*N+2)/6)+2.
80
--      The slice distribution will vary, and depends on the control set restrictions and LUT-FF pairs resulting from map+p&r.
81
--
82
--      This design was originally targeted to a Spartan-6 platform, synthesized with XST and normal constraints.
83
--      The VHDL dialect used is VHDL'93, accepted largely by all synthesis tools.
84
--
85
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
86
--                                                                   
87
--                                                                   
88
--      Author(s):      Jonny Doin, jdoin@opencores.org
89
--                                                                   
90
--      Copyright (C) 2011 Authors
91
--      --------------------------
92
--                                                                   
93
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
94
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
95
--      disclaimer. 
96
--                                                                   
97
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
98
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
99
--      (at your option) any later version.
100
--                                                                   
101
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
102
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
103
--      details.
104
--
105
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
106
--      it from http://www.opencores.org/lgpl.shtml
107
--                                                                   
108
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
109
--
110
-- 2011/07/06   v0.01.0010  [JD]    started development. verification of synthesis circuit inference.
111
-- 2011/07/07   v1.00.0020  [JD]    verification in silicon. operation at 100MHz, tested on the Atlys board (Spartan-6 LX45).
112
--
113
-----------------------------------------------------------------------------------------------------------------------
114
--  TODO
115
--  ====
116
--
117
--
118
-----------------------------------------------------------------------------------------------------------------------
119
library ieee;
120
use ieee.std_logic_1164.all;
121
 
122
entity grp_debouncer is
123
    Generic (
124
        N : positive := 8;                                                      -- input bus width
125
        CNT_VAL : positive := 10000);                                           -- clock counts for debounce period
126
    Port (
127
        clk_i : in std_logic := 'X';                                            -- system clock
128
        data_i : in std_logic_vector (N-1 downto 0) := (others => 'X');         -- noisy input data
129
        data_o : out std_logic_vector (N-1 downto 0);                           -- registered stable output data
130
        strb_o : out std_logic                                                  -- strobe for new data available
131
    );
132
end grp_debouncer;
133
 
134
architecture rtl of grp_debouncer is
135
    -- datapath pipeline 
136
    signal reg_A, reg_B : std_logic_vector (N-1 downto 0) := (others => '0');   -- debounce edge detectors
137
    signal reg_out : std_logic_vector (N-1 downto 0) := (others => '0');        -- registered output
138
    signal dat_strb : std_logic := '0';                                         -- data transfer strobe
139
    signal dat_diff : std_logic := '0';                                         -- edge detector
140
    -- debounce counter
141
    signal cnt_reg : integer range CNT_VAL downto 0 := 0;                       -- debounce period counter
142
    signal cnt_next : integer range CNT_VAL downto 0 := 0;                      -- combinatorial signal
143
begin
144
 
145
    --=============================================================================================
146
    -- DEBOUNCE COUNTER LOGIC
147
    --=============================================================================================
148
    -- This counter is implemented as a up-counter with reset and final count detection via compare,
149
    -- instead of a down-counter with preset and final count detection via nonzero detection.
150
    -- This is better for Spartan-6 and Virtex-6 CLB architecture, because it uses less control sets.
151
    --
152
    -- cnt_reg register transfer logic
153
    cnt_reg_proc: process (clk_i) is
154
    begin
155
        if clk_i'event and clk_i = '1' then
156
            cnt_reg <= cnt_next;
157
        end if;
158
    end process cnt_reg_proc;
159
    -- cnt_next combinatorial logic
160
    cnt_next_proc: cnt_next <=  0 when dat_diff = '1' or dat_strb = '1' else cnt_reg + 1;
161
    -- final count combinatorial logic
162
    final_cnt_proc: dat_strb <= '1' when cnt_reg = CNT_VAL else '0';
163
 
164
    --=============================================================================================
165
    -- DATAPATH SIGNAL PIPELINE
166
    --=============================================================================================
167
    -- input pipeline logic
168
    pipeline_proc: process (clk_i) is
169
    begin
170
        -- edge detection pipeline
171
        if clk_i'event and clk_i = '1' then
172
            reg_A <= data_i;
173
            reg_B <= reg_A;
174
        end if;
175
        if clk_i'event and clk_i = '1' then
176
            if dat_strb = '1' then
177
                reg_out <= reg_B;
178
            end if;
179
        end if;
180
    end process pipeline_proc;
181
    -- edge detector
182
    edge_detector_proc: dat_diff <= '1' when reg_A /= reg_B else '0';
183
 
184
    --=============================================================================================
185
    -- OUTPUT LOGIC
186
    --=============================================================================================
187
    -- new data strobe detection
188
    strb_o_proc:    strb_o <= '1' when ((reg_out /= reg_B) and dat_strb = '1') else '0';
189
    -- connect output ports
190
    data_o_proc:    data_o <= reg_out;
191
 
192
end rtl;
193
 

powered by: WebSVN 2.1.0

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