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 12

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

Line No. Rev Author Line
1 5 jdoin
-----------------------------------------------------------------------------------------------------------------------
2 12 jdoin
-- Author:          Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com
3 5 jdoin
-- 
4
-- Create Date:     09:56:30 07/06/2011  
5
-- Module Name:     grp_debouncer - RTL
6 10 jdoin
-- Project Name:    basic functions
7 5 jdoin
-- 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 7 jdoin
--                                                                                     
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 5 jdoin
--      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 12 jdoin
--      Verification in silicon was done on a Digilent Atlys board with a Spartan-6 FPGA @100MHz clk_i.
84 5 jdoin
--      The VHDL dialect used is VHDL'93, accepted largely by all synthesis tools.
85
--
86
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
87
--                                                                   
88 10 jdoin
--                                                                   
89 12 jdoin
--      Author(s):      Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com
90 10 jdoin
--                                                                   
91 5 jdoin
--      Copyright (C) 2011 Authors
92 10 jdoin
--      --------------------------
93
--                                                                   
94
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
95 5 jdoin
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
96 10 jdoin
--      disclaimer. 
97
--                                                                   
98 5 jdoin
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
99
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
100 10 jdoin
--      (at your option) any later version.
101
--                                                                   
102
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
103
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
104
--      details.
105
--
106 5 jdoin
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
107 10 jdoin
--      it from http://www.opencores.org/lgpl.shtml
108 5 jdoin
--                                                                   
109
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
110
--
111
-- 2011/07/06   v0.01.0010  [JD]    started development. verification of synthesis circuit inference.
112
-- 2011/07/07   v1.00.0020  [JD]    verification in silicon. operation at 100MHz, tested on the Atlys board (Spartan-6 LX45).
113
--
114
-----------------------------------------------------------------------------------------------------------------------
115
--  TODO
116
--  ====
117
--
118 12 jdoin
--  The circuit can easily be extended to have a signature of which inputs changed at the data out port.
119 5 jdoin
--
120
-----------------------------------------------------------------------------------------------------------------------
121
library ieee;
122
use ieee.std_logic_1164.all;
123
 
124
entity grp_debouncer is
125
    Generic (
126
        N : positive := 8;                                                      -- input bus width
127
        CNT_VAL : positive := 10000);                                           -- clock counts for debounce period
128
    Port (
129
        clk_i : in std_logic := 'X';                                            -- system clock
130
        data_i : in std_logic_vector (N-1 downto 0) := (others => 'X');         -- noisy input data
131
        data_o : out std_logic_vector (N-1 downto 0);                           -- registered stable output data
132
        strb_o : out std_logic                                                  -- strobe for new data available
133
    );
134
end grp_debouncer;
135
 
136
architecture rtl of grp_debouncer is
137
    -- datapath pipeline 
138
    signal reg_A, reg_B : std_logic_vector (N-1 downto 0) := (others => '0');   -- debounce edge detectors
139
    signal reg_out : std_logic_vector (N-1 downto 0) := (others => '0');        -- registered output
140
    signal dat_strb : std_logic := '0';                                         -- data transfer strobe
141
    signal dat_diff : std_logic := '0';                                         -- edge detector
142
    -- debounce counter
143
    signal cnt_reg : integer range CNT_VAL downto 0 := 0;                       -- debounce period counter
144
    signal cnt_next : integer range CNT_VAL downto 0 := 0;                      -- combinatorial signal
145
begin
146
 
147
    --=============================================================================================
148
    -- DEBOUNCE COUNTER LOGIC
149
    --=============================================================================================
150
    -- This counter is implemented as a up-counter with reset and final count detection via compare,
151
    -- instead of a down-counter with preset and final count detection via nonzero detection.
152
    -- This is better for Spartan-6 and Virtex-6 CLB architecture, because it uses less control sets.
153
    --
154
    -- cnt_reg register transfer logic
155
    cnt_reg_proc: process (clk_i) is
156
    begin
157
        if clk_i'event and clk_i = '1' then
158
            cnt_reg <= cnt_next;
159
        end if;
160
    end process cnt_reg_proc;
161
    -- cnt_next combinatorial logic
162
    cnt_next_proc: cnt_next <=  0 when dat_diff = '1' or dat_strb = '1' else cnt_reg + 1;
163
    -- final count combinatorial logic
164
    final_cnt_proc: dat_strb <= '1' when cnt_reg = CNT_VAL else '0';
165
 
166
    --=============================================================================================
167
    -- DATAPATH SIGNAL PIPELINE
168
    --=============================================================================================
169
    -- input pipeline logic
170
    pipeline_proc: process (clk_i) is
171
    begin
172
        -- edge detection pipeline
173
        if clk_i'event and clk_i = '1' then
174
            reg_A <= data_i;
175
            reg_B <= reg_A;
176
        end if;
177
        if clk_i'event and clk_i = '1' then
178
            if dat_strb = '1' then
179
                reg_out <= reg_B;
180
            end if;
181
        end if;
182
    end process pipeline_proc;
183
    -- edge detector
184
    edge_detector_proc: dat_diff <= '1' when reg_A /= reg_B else '0';
185
 
186
    --=============================================================================================
187
    -- OUTPUT LOGIC
188
    --=============================================================================================
189
    -- new data strobe detection
190
    strb_o_proc:    strb_o <= '1' when ((reg_out /= reg_B) and dat_strb = '1') else '0';
191
    -- connect output ports
192
    data_o_proc:    data_o <= reg_out;
193
 
194
end rtl;
195
 

powered by: WebSVN 2.1.0

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