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

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src/] [filter.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sshuv2
 
2
--==============================================================================
3
--                                                                             |
4
--    Project: IIC Multiple Bus Controller (IICMB)                             |
5
--                                                                             |
6
--    Module:  Digital filter with hysteresis.                                 |
7
--    Version:                                                                 |
8
--             1.0,   April 29, 2016                                           |
9
--                                                                             |
10
--    Author:  Sergey Shuvalkin, (sshuv2@opencores.org)                        |
11
--                                                                             |
12
--==============================================================================
13
--==============================================================================
14
-- Copyright (c) 2016, Sergey Shuvalkin                                        |
15
-- All rights reserved.                                                        |
16
--                                                                             |
17
-- Redistribution and use in source and binary forms, with or without          |
18
-- modification, are permitted provided that the following conditions are met: |
19
--                                                                             |
20
-- 1. Redistributions of source code must retain the above copyright notice,   |
21
--    this list of conditions and the following disclaimer.                    |
22
-- 2. Redistributions in binary form must reproduce the above copyright        |
23
--    notice, this list of conditions and the following disclaimer in the      |
24
--    documentation and/or other materials provided with the distribution.     |
25
--                                                                             |
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   |
28
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  |
29
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE    |
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         |
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        |
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    |
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     |
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     |
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  |
36
-- POSSIBILITY OF SUCH DAMAGE.                                                 |
37
--==============================================================================
38
 
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
 
43
 
44
--==============================================================================
45
entity filter is
46
  generic
47
  (
48
    g_cycles           :       positive         := 10    -- Number of levels to receive before toggling output
49
  );
50
  port
51
  (
52
    -------------------------------------
53
    clk                : in    std_logic;                -- Clock
54
    s_rst              : in    std_logic;                -- Synchronous reset
55
    -------------------------------------
56
    -------------------------------------
57
    sig_in             : in    std_logic;                -- Input signal
58
    sig_out            :   out std_logic                 -- Output (filtered) signal
59
    -------------------------------------
60
  );
61
end entity filter;
62
--==============================================================================
63
 
64
--==============================================================================
65
architecture rtl of filter is
66
 
67
  signal   sig_out_y : std_logic                   := '1';
68
  signal   cnt       : integer range 0 to g_cycles := g_cycles;
69
 
70
begin
71
 
72
  ------------------------------------------------------------------------------
73
  sig_out_y_proc:
74
  process(clk)
75
  begin
76
    if rising_edge(clk) then
77
      if (s_rst = '1') then
78
        sig_out_y <= '1';
79
        cnt       <= g_cycles;
80
      else
81
        if (sig_in = '1') then
82
          if (cnt /= g_cycles) then
83
            cnt <= cnt + 1;
84
          end if;
85
        else
86
          if (cnt /= 0) then
87
            cnt <= cnt - 1;
88
          end if;
89
        end if;
90
 
91
        if (sig_out_y = '1') then
92
          if (sig_in = '0')and(cnt = 1) then
93
            sig_out_y <= '0';
94
          end if;
95
        else
96
          if (sig_in = '1')and(cnt = (g_cycles - 1)) then
97
            sig_out_y <= '1';
98
          end if;
99
        end if;
100
      end if;
101
    end if;
102
  end process sig_out_y_proc;
103
  ------------------------------------------------------------------------------
104
 
105
  sig_out <= sig_out_y;
106
 
107
end rtl;
108
--==============================================================================
109
 

powered by: WebSVN 2.1.0

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