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

Subversion Repositories wb_uart

[/] [wb_uart/] [trunk/] [src/] [slib_mv_filter.vhd] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 federico.a
--
2
-- Majority voting filter
3
--
4
-- Author:   Sebastian Witt
5
-- Date:     27.01.2008
6
-- Version:  1.1
7
--
8
-- This code is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU Lesser General Public
10
-- License as published by the Free Software Foundation; either
11
-- version 2.1 of the License, or (at your option) any later version.
12
--
13
-- This code is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
-- Lesser General Public License for more details.
17
--
18
-- You should have received a copy of the GNU Lesser General Public
19
-- License along with this library; if not, write to the
20
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
21
-- Boston, MA  02111-1307  USA
22
--
23
 
24
LIBRARY IEEE;
25
USE IEEE.std_logic_1164.all;
26
USE IEEE.numeric_std.all;
27
 
28
 
29
entity slib_mv_filter is
30
    generic (
31
        WIDTH       : natural := 4;
32
        THRESHOLD   : natural := 10
33
    );
34
    port (
35
        CLK         : in std_logic;                             -- Clock
36
        RST         : in std_logic;                             -- Reset
37
        SAMPLE      : in std_logic;                             -- Clock enable for sample process
38
        CLEAR       : in std_logic;                             -- Reset process
39
        D           : in std_logic;                             -- Signal input
40
        Q           : out std_logic                             -- Signal D was at least THRESHOLD samples high
41
    );
42
end slib_mv_filter;
43
 
44
architecture rtl of slib_mv_filter is
45
 
46
    -- Signals
47
    signal iCounter     : unsigned(WIDTH downto 0);             -- Sample counter
48
    signal iQ           : std_logic;                            -- Internal Q
49
 
50
begin
51
    -- Main process
52
    MV_PROC: process (RST, CLK)
53
    begin
54
        if (RST = '1') then
55
            iCounter  <= (others => '0');
56
            iQ        <= '0';
57
        elsif (CLK'event and CLK='1') then
58
            if (iCounter >= THRESHOLD) then                     -- Compare with threshold
59
                iQ <= '1';
60
            else
61
                if (SAMPLE = '1' and D = '1') then              -- Take sample
62
                    iCounter <= iCounter + 1;
63
                end if;
64
            end if;
65
 
66
            if (CLEAR = '1') then                               -- Reset logic
67
                iCounter  <= (others => '0');
68
                iQ        <= '0';
69
            end if;
70
 
71
        end if;
72
    end process;
73
 
74
    -- Output signals
75
    Q <= iQ;
76
 
77
end rtl;
78
 

powered by: WebSVN 2.1.0

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