-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgc_dyn_glitch_filt.vhd
113 lines (100 loc) · 3.8 KB
/
gc_dyn_glitch_filt.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--==============================================================================
-- CERN (BE-CO-HT)
-- Glitch filter with dynamically selectable length
--==============================================================================
--
-- author: Theodor Stana (t.stana@cern.ch)
-- Matthieu Cattin (matthieu.cattin@cern.ch)
--
-- date of creation: 2014-03-13
--
-- version: 1.0
--
-- description:
-- Glitch filter consisting of a set of chained flip-flops followed by a
-- comparator. The comparator toggles to '1' when all FFs in the chain are
-- '1' and respectively to '0' when all the FFS in the chain are '0'.
-- Latency = len_i + 1.
--
-- dependencies:
--
-- references:
-- Based on gc_glitch_filter.vhd
--
--==============================================================================
-- GNU LESSER GENERAL PUBLIC LICENSE
--==============================================================================
-- This source file is free software; you can redistribute it and/or modify it
-- under the terms of the GNU Lesser General Public License as published by the
-- Free Software Foundation; either version 2.1 of the License, or (at your
-- option) any later version. This source is distributed in the hope that it
-- will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU Lesser General Public License for more details. You should have
-- received a copy of the GNU Lesser General Public License along with this
-- source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
--==============================================================================
-- TODO: -
--==============================================================================
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.gencores_pkg.all;
entity gc_dyn_glitch_filt is
generic
(
-- Number of bit of the glitch filter length input
g_len_width : natural := 8
);
port
(
clk_i : in std_logic;
rst_n_i : in std_logic;
-- Glitch filter length
len_i : in std_logic_vector(g_len_width-1 downto 0);
-- Data input, synchronous to clk_i
dat_i : in std_logic;
-- Data output
-- latency: g_len+1 clk_i cycles
dat_o : out std_logic
);
end entity gc_dyn_glitch_filt;
architecture behav of gc_dyn_glitch_filt is
--============================================================================
-- Signal declarations
--============================================================================
signal filt_cnt : unsigned(g_len_width-1 downto 0);
--==============================================================================
-- architecture begin
--==============================================================================
begin
-- Glitch filter
p_glitch_filt : process (clk_i)
begin
if rising_edge (clk_i) then
if rst_n_i = '0' then
filt_cnt <= unsigned(len_i) srl 1; -- middle value
dat_o <= '0';
else
-- Arrival of a '0'
if dat_i = '0' then
if filt_cnt /= 0 then -- counter updated
filt_cnt <= filt_cnt - 1;
else
dat_o <= '0'; -- output updated
end if;
-- Arrival of a '1'
elsif dat_i = '1' then
if filt_cnt /= unsigned(len_i) then
filt_cnt <= filt_cnt + 1; -- counter updated
else
dat_o <= '1'; -- output updated
end if;
end if;
end if;
end if;
end process p_glitch_filt;
end architecture behav;
--==============================================================================
-- architecture end
--==============================================================================