From c6726baa7af8a656c13e2e4d57ecdeecc157a24b Mon Sep 17 00:00:00 2001 From: Twister10000 <82016318+Twister10000@users.noreply.github.com> Date: Sun, 8 Dec 2024 16:05:21 +0100 Subject: [PATCH] Fixed Timing error with debounce.vhd The asynchronous reset causes a latch, which is interpreted by Quartus as a clock. --- sd_v3/source/vhdl_lib/debounce.vhd | 81 ++++++++++++++++-------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/sd_v3/source/vhdl_lib/debounce.vhd b/sd_v3/source/vhdl_lib/debounce.vhd index 4c0836e..3c8e360 100644 --- a/sd_v3/source/vhdl_lib/debounce.vhd +++ b/sd_v3/source/vhdl_lib/debounce.vhd @@ -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; \ No newline at end of file