Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Timing error with debounce.vhd #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 44 additions & 37 deletions sd_v3/source/vhdl_lib/debounce.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,56 @@ begin
debounced <= last;

debounce_process: process(rst, clk, key)
begin
if rst = '0' then
s_tick <= '0';
val_s <= 0;
last <= key;
else
--#############################
--#############################
if last = key then
val_s <= 0;
begin

elsif clk'event and clk = '1' then
if clk'event and clk = '1' then
if clk_en = '1' then
--======================
case val_s is
when n =>
---------------
if key = '0' then
s_tick <= '1';
end if;
last <= key;
val_s <= 0;
---------------
when others =>
val_s <= val_s + 1;
end case;
--======================

--======================
case val_s is
when n =>
---------------
if key = '0' then
s_tick <= '1';
end if;
last <= key;
val_s <= 0;
---------------
when others =>
val_s <= val_s + 1;
end case;
--======================

end if;
if rst = '0' then
s_tick <= '0';
val_s <= 0;
last <= key;
else
if last = key then
val_s <= 0;
end if;
end if;
end if;
end if;

--#############################
--#############################
if clk'event and clk = '1' then
if clk_en = '1' then
--#############################
--#############################
if clk'event and clk = '1' then
if clk_en = '1' then
--======================
if s_tick = '1' then
s_tick <= '0';
s_tick <= '0';
end if;
--======================
end if;
end if;

end if;
end process;
end debounce_a;
if rst = '0' then
s_tick <= '0';
val_s <= 0;
last <= key;
else
if last = key then
val_s <= 0;
end if;
end if;
end if;
end process;
end debounce_a;