以莫爾機控制0~3上下數計數器VHDL20240608_counting_moore https://youtube.com/shorts/NGUJQK7pRxM 利用莫爾機完成一個0~3上下數計數器 當按下rst,計數器輸出為0 放開rst,計數器正常計數 當mode為0,為下數計數器,0, 3, 2, 1, 0 當mode為1,為上數計數器,0, 1, 2, 3, 0 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; use ieee.numeric_std.all; entity VHDL20240608_counting_moore is port( clk_4M:in std_logic; rst:in std_logic; mode:in std_logic; BCD:out std_logic_vector(3 downto 0)); end VHDL20240608_counting_moore; architecture aa of VHDL20240608_counting_moore is signal cnt1:integer range 0 to 1999999:=0; signal clk_sec:std_logic:='0'; type state_type is (s0, s1, s2, s3); signal state: state_type:=s0; begin process(clk_4M) begin if rising_edge(clk_4M) then if cnt1=1999999 then cnt1<=0; clk_sec<=not clk_sec; else cnt1<=cnt1+1; end if; end if; end process; process(rst,clk_sec,state,mode) begin if rst='0' then state<=s0;