【发布时间】:2014-06-19 12:42:25
【问题描述】:
我有一个有 6 个状态(3 个主要状态)的状态机。只有最后一个状态有效,但前 2 个没有(共 3 个)。只有最后一个状态有效。我发现了问题,当我移除去抖电路时它可以工作,但我需要去抖电路。我从互联网上得到了去抖电路。如果有人可以提供帮助,我会很高兴。
type SM_STATES is (state_column_1, scan_col_1, state_column_2, scan_col_2,
state_column_3, scan_col_3);
signal my_state : SM_STATES := state_column_1;
下面是状态机:
scanner_sm : process (clk)
begin -- process key_scanner
if clk'event and clk = '1' then
if state_inc = '1' then -- clock divider finished counting down 100000
-- reset scan_complete
scan_complete <= '0';
case my_state is
when state_column_1 =>
scanned_val <= (others => '0');
original_col <= "110";
my_state <= scan_col_1;
when scan_col_1 =>
case bcd_val is
when "1110" => scanned_val <= "1100100"; -- 1 wrong
when "1101" => scanned_val <= "1100010"; -- 2 wrong
when others => scanned_val <= "0010000";
end case;
my_state <= state_column_2;
when state_column_2 =>
original_col <= "011";
my_state <= scan_col_2;
when scan_col_2 =>
case bcd_val is
when "1110" => scanned_val <= "1011011"; -- 5 wrong
when "1101" => scanned_val <= "1011111"; -- 6 wrong
when others => scanned_val <= "0000000";
end case;
my_state <= state_column_3;
when state_column_3 =>
original_col <= "101";
my_state <= scan_col_3;
when scan_col_3 => -- Reading S1 // The only working state
case bcd_val is
when "1110" => scanned_val <= "1100000"; -- 9/ 1
when "1101" => scanned_val <= "0111110"; -- X/ 2
when others => scanned_val <= "0000000";
end case;
my_state <= state_column_1; -- ************ Error might be here
scan_complete <= '1'; -- ********** Error might be here
when others => scanned_val <= "0000000";
end case;
end if;
end if;
end process scanner_sm;
debounce: process (CLK) is
begin
if (CLK'event and CLK = '1') then
Q0 <= scannel_val;
Q1 <= Q0;
Q2 <= Q1;
end if;
end process;
Final_val <= Q0 and Q1 and (not Q2);
end Behavioral;
【问题讨论】:
-
你为什么在 Stackoverlow 和 Stackexchange 上都发布这个?没有足够的源代码来回答,演示“只有最后一个状态正在工作,但前 2 个没有(共 3 个)”。要么包括一个工作测试台,要么显示一个(希望是高分辨率的)波形图像。
-
我添加了我的完整流程。我只有一个 top_level,我用互联网上的例子写了它,这是我写的第一个。我无法编写完整的源代码。我知道那没有意义,但我不能......
标签: vhdl state-machine fsm case-when