Witam. Mam zrobić taki projekt w VHDL:
http://www.ue.eti.pg.gda.pl/~wujek/lab_prog/zadania/zad_stoper.html
i mam problem z napisaniem modułu zapobiegającego drganiu przycisku. Może mi ktoś pomóc go napisać? Oto moj kod kótry napisałem, pomiar działa ale niestety nie bardzo zapobiega temu drganiu i nie zawsze działa poprawnie:
http://www.ue.eti.pg.gda.pl/~wujek/lab_prog/zadania/zad_stoper.html
i mam problem z napisaniem modułu zapobiegającego drganiu przycisku. Może mi ktoś pomóc go napisać? Oto moj kod kótry napisałem, pomiar działa ale niestety nie bardzo zapobiega temu drganiu i nie zawsze działa poprawnie:
--{{ Section below this comment is automatically maintained
-- and may be overwritten
--{entity {pomiar} architecture {pomiar}}
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity dzielnik is
generic (n : positive := 3000000);
port(
clk_in_dzielnik : in STD_LOGIC;
rst_dzielnik : in STD_LOGIC;
wyj: out STD_LOGIC
);
end dzielnik;
--}} End of automatically maintained section
architecture dzielnik of dzielnik is
begin
process(clk_in_dzielnik, rst_dzielnik)
variable Q1 : INTEGER RANGE 0 to n;
variable Q2 : INTEGER RANGE 0 to n;
begin
if (rst_dzielnik = '0') then
if clk_in_dzielnik'event and clk_in_dzielnik='1' then
if Q1 < n then
Q1 := Q1 + 1;
wyj <= '1';
Q2 := n;
else
Q2 := Q2 - 1;
wyj <= '0';
if Q2 = 0 then
Q1 := 0;
end if;
end if;
end if;
else
wyj <= '0';
end if;
end process;
end dzielnik;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Syntax for Synopsys FPGA Express
-- pragma translate_off
library unisim;
use unisim.vcomponents.all;
-- pragma translate_on
entity czas is
port(
clk_in : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR (6 downto 0);
cpu_rst : out STD_LOGIC;
ram_cs : out STD_LOGIC;
rst : in STD_LOGIC;
start_stop_button : in STD_LOGIC
);
end czas;
architecture czas of czas is
type Stan_Matrix is array(0 to 10) of std_logic_vector(6 downto 0);
signal filtr_out : STD_LOGIC;
signal liczStany_out : STD_LOGIC;
signal liczba_przycisniec : STD_LOGIC_VECTOR(1 downto 0);
signal clk_d: std_logic;
signal clk_in2,clk_in3 : std_logic;
signal rst_buf,ram_cs_buf,cpu_rst_buf : std_logic;
signal wy : std_logic_vector(6 downto 0);
constant Stan:Stan_Matrix:=(
"1110111", --0
"0010010", --1
"1011101", --2
"1011011", --3
"0111010", --4
"1101011", --5
"1101111", --6
"1010010", --7
"1111111", --8
"1111011", --9
"1101101" --E
);
component dzielnik is
port(
clk_in_dzielnik, rst_dzielnik : in std_logic;
wyj : out std_logic
);
end component;
component BUFG
port(
O : out STD_ULOGIC;
I : in STD_ULOGIC);
end component;
component IBUF is
port(
O : out STD_ULOGIC;
I : in STD_ULOGIC);
end component;
component OBUF is
port(
O : out STD_ULOGIC;
I : in STD_ULOGIC);
end component;
begin
ibuf_1: ibuf port map (I => clk_in, O => clk_in3);
bufg_1: bufg port map (I => clk_in3,O => clk_in2);
ibuf_2: ibuf port map (I => rst, O => rst_buf);
dziel: dzielnik port map (clk_in_dzielnik => clk_in2, rst_dzielnik => rst_buf, wyj => clk_d );
filtr: process(start_stop_button, clk_in2) is
variable tlum: INTEGER range 0 to 3 := 0;
begin
if (clk_in2'event and clk_in2 = '1') then
if (tlum = 3) then
if (start_stop_button = '0') then
filtr_out <= '1';
else
filtr_out <= '0';
end if;
if (start_stop_button = '1') then
tlum := 0;
end if;
else
if (start_stop_button = '0') then
if (tlum = 3) then
tlum := 3;
else
tlum := tlum + 1;
end if;
end if;
end if;
end if;
end process filtr;
liczStany: process(filtr_out, rst_buf) is
begin
if (rst_buf='1') then
liczba_przycisniec <= "01";
elsif (filtr_out'event and filtr_out='1') then
if liczba_przycisniec = "01" then
liczba_przycisniec <= "10";
elsif liczba_przycisniec = "10" then
liczba_przycisniec <= "11";
else
liczba_przycisniec <= "01";
end if;
end if;
end process liczStany;
liczCzas: process(clk_d, liczba_przycisniec) is
variable count: INTEGER range 0 to 10;
begin
if (clk_d'event and clk_d='1') then
if (liczba_przycisniec = "10") then
if count = 0 then
count := 1;
wy <= Stan(count);
elsif count = 1 then
count := 2;
wy <= Stan(count);
elsif count = 2 then
count := 3;
wy <= Stan(count);
elsif count = 3 then
count := 4;
wy <= Stan(count);
elsif count = 4 then
count := 5;
wy <= Stan(count);
elsif count = 5 then
count := 6;
wy <= Stan(count);
elsif count = 6 then
count := 7;
wy <= Stan(count);
elsif count = 7 then
count := 8;
wy <= Stan(count);
elsif count = 8 then
count := 9;
wy <= Stan(count);
else
count := 10;
wy <= Stan(count);
end if;
elsif (liczba_przycisniec = "11") then
wy <= Stan(count);
else
wy <= Stan(0);
count := 0;
end if;
end if;
end process liczCzas;
ram_cs_buf <= '1';
cpu_rst_buf <= '1';
obuf_1: obuf port map (I => ram_cs_buf, O => ram_cs);
obuf_2: obuf port map (I => cpu_rst_buf, O => cpu_rst);
obuf_3: obuf port map (I => wy(0), O => data_out(0));
obuf_4: obuf port map (I => wy(1), O => data_out(1));
obuf_5: obuf port map (I => wy(2), O => data_out(2));
obuf_6: obuf port map (I => wy(3), O => data_out(3));
obuf_7: obuf port map (I => wy(4), O => data_out(4));
obuf_8: obuf port map (I => wy(5), O => data_out(5));
obuf_9: obuf port map (I => wy(6), O => data_out(6));
end czas;