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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [button_db.vhd] - Blame information for rev 239

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

Line No. Rev Author Line
1 191 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  button_db
25
-- Description:  Debounces a single button/switch and provides a change of
26
--                state signal as well as registered level.
27 218 jshamlet
--
28
-- Revision History
29
-- Author          Date     Change
30
------------------ -------- ---------------------------------------------------
31
-- Seth Henry      04/14/20 Code cleanup and revision section added
32 191 jshamlet
 
33
library ieee;
34
  use ieee.std_logic_1164.all;
35
  use ieee.std_logic_unsigned.all;
36
  use ieee.std_logic_misc.all;
37
 
38
entity button_db is
39
generic(
40
  Button_Level          : std_logic;
41
  Reset_Level           : std_logic
42
);
43
port(
44
  Clock                 : in  std_logic;
45
  Reset                 : in  std_logic;
46
  mSec_Tick             : in  std_logic;
47
  --
48
  Button_In             : in  std_logic;
49
  --
50
  Button_Pressed        : out std_logic;
51
  Button_CoS            : out std_logic
52
);
53
end entity;
54
 
55
architecture behave of button_db is
56
 
57
  signal Button_SR      : std_logic_vector(2 downto 0);
58
  alias  Button_In_q    is Button_SR(2);
59
 
60
  signal Button_Dn_Tmr  : std_logic_vector(5 downto 0);
61
  signal Button_Dn      : std_logic;
62
 
63
  signal Button_Up_Tmr  : std_logic_vector(5 downto 0);
64
  signal Button_Up      : std_logic;
65
 
66
  signal Button_State   : std_logic;
67
  signal Button_State_q : std_logic;
68
 
69
begin
70
 
71
  Button_Pressed         <= Button_State_q;
72
 
73
  Button_trap: process( Clock, Reset )
74
  begin
75
    if( Reset = Reset_Level )then
76
      Button_SR          <= (others => '0');
77
 
78
      Button_Dn_Tmr      <= (others => '0');
79
      Button_Dn          <= '0';
80
 
81
      Button_Up_Tmr      <= (others => '0');
82
      Button_Up          <= '0';
83
 
84
      Button_State       <= '0';
85
      Button_State_q     <= '0';
86
 
87
      Button_CoS         <= '0';
88
    elsif( rising_edge(Clock) )then
89
      Button_SR         <= Button_SR(1 downto 0) & Button_In;
90
 
91
      Button_Dn_Tmr     <= (others => '0');
92
      Button_Dn         <= '0';
93
      if( Button_In_q = Button_Level )then
94
        Button_Dn_Tmr   <= Button_Dn_Tmr + mSec_Tick;
95
        if( and_reduce(Button_Dn_Tmr) = '1' )then
96
          Button_Dn_Tmr <= Button_Dn_Tmr;
97
          Button_Dn     <= '1';
98
        end if;
99
      end if;
100
 
101
      Button_Up_Tmr     <= (others => '0');
102
      Button_Up         <= '0';
103
      if( Button_In_q = not Button_Level )then
104
        Button_Up_Tmr   <= Button_Up_Tmr + mSec_Tick;
105
        if( and_reduce(Button_Up_Tmr) = '1' )then
106
          Button_Up_Tmr <= Button_Up_Tmr;
107
          Button_Up     <= '1';
108
        end if;
109
      end if;
110
 
111
      if( Button_Dn = '1' )then
112
        Button_State    <= '1';
113
      elsif( Button_Up  = '1' )then
114
        Button_State    <= '0';
115
      end if;
116
 
117
      Button_State_q    <= Button_State;
118
      Button_CoS        <= Button_State xor Button_State_q;
119
 
120
    end if;
121
  end process;
122
 
123
end architecture;

powered by: WebSVN 2.1.0

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