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

Subversion Repositories pdp1

[/] [pdp1/] [trunk/] [rtl/] [vhdl/] [debounce.vhd] - Diff between revs 3 and 8

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 8
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
-- Company: 
-- Company: 
-- Engineer: Yann Vernier
-- Engineer: Yann Vernier
-- 
-- 
-- Create Date:    23:05:04 09/08/2009 
-- Create Date:    23:05:04 09/08/2009 
-- Design Name: 
-- Design Name: 
-- Module Name:    debounce - Behavioral 
-- Module Name:    debounce - Behavioral 
-- Project Name: 
-- Project Name: 
-- Target Devices: 
-- Target Devices: 
-- Tool versions: 
-- Tool versions: 
-- Description: Debounces an input signal (for instance, a switch).
-- Description: Debounces an input signal (for instance, a switch).
--          Output will only change after input has stayed one value between two enabled clock edges.
--          Output will only change after input has stayed one value between two enabled clock edges.
--
--
-- Dependencies: 
-- Dependencies: 
--
--
-- Revision: 
-- Revision: 
-- Revision 0.01 - File Created
-- Revision 0.01 - File Created
-- Additional Comments: 
-- Additional Comments: 
--
--
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
library IEEE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_1164.ALL;
 
 
entity debounce is
entity debounce is
    Port ( clk : in  STD_LOGIC;
    Port ( clk : in  STD_LOGIC;
           clken : in  STD_LOGIC;
           clken : in  STD_LOGIC;
           input : in  STD_LOGIC;
           input : in  STD_LOGIC;
           output : inout  STD_LOGIC);
           output : out  STD_LOGIC);
end debounce;
end debounce;
 
 
-- Concept: input values are asynchronously connected to SR latches.
-- Concept: input values are asynchronously connected to SR latches.
-- Those are synchronously reset, so if both are set, the input is unstable.
-- Those are synchronously reset, so if both are set, the input is unstable.
-- On Spartan 3 FPGAs, this architecture probably requires at least three slices,
-- On Spartan 3 FPGAs, this architecture probably requires at least three slices,
-- due to separate RS lines for flip-flops. The output register may share, though.
-- due to separate RS lines for flip-flops. The output register may share, though.
architecture Behavioral of debounce is
architecture Behavioral of debounce is
        -- 00->no input value observed (reset), 10 or 01 -> steady value, 11->value changed
        -- 00->no input value observed (reset), 10 or 01 -> steady value, 11->value changed
        signal inputv : std_logic_vector(0 to 1) := "00";
        signal inputv : std_logic_vector(0 to 1) := "00";
        signal next_output : std_logic;
        signal next_output : std_logic;
 
        signal current_output : std_logic;
begin
begin
 
        output <= current_output;
        -- our two asynch latches must agree for an update to occur
        -- our two asynch latches must agree for an update to occur
        -- the tricky part of the code was convincing the synthesizer we only need one LUT3
        -- the tricky part of the code was convincing the synthesizer we only need one LUT3
        -- to implement this consensus function (inputv must agree to alter output).
        -- to implement this consensus function (inputv must agree to alter output).
        with inputv select
        with inputv select
                next_output <= '0' when "10",
                next_output <= '0' when "10",
                                                                                '1' when "01",
                                                                                '1' when "01",
                                                                                output when others;
                                                                                current_output when others;
        process (clk, input)
        process (clk, input)
        begin
        begin
                -- input='0' for asynch set of input(0), synch reset
                -- input='0' for asynch set of input(0), synch reset
                if input='0' then
                if input='0' then
                        inputv(0) <= '1';
                        inputv(0) <= '1';
                elsif clken='1' and rising_edge(clk) then
                elsif clken='1' and rising_edge(clk) then
                        inputv(0) <= '0';
                        inputv(0) <= '0';
                end if;
                end if;
                -- same for 1
                -- same for 1
                if input='1' then
                if input='1' then
                        inputv(1) <= '1';
                        inputv(1) <= '1';
                elsif clken='1' and rising_edge(clk) then
                elsif clken='1' and rising_edge(clk) then
                        inputv(1) <= '0';
                        inputv(1) <= '0';
                end if;
                end if;
                -- finally, on enabled clocks, update output
                -- finally, on enabled clocks, update output
                if clken='1' and rising_edge(clk) then
                if clken='1' and rising_edge(clk) then
                        output <= next_output;
                        current_output <= next_output;
                end if;
                end if;
        end process;
        end process;
end Behavioral;
end Behavioral;
 
 

powered by: WebSVN 2.1.0

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