HTML Code:
library ieee ; use ieee.std_logic_1164.all ; ----------------------------- entity state_circuit is port ( clk1 : in std_logic ; key : in std_logic_vector( 2 downto 0 ); outp: out std_logic ) ; end state_circuit ; --------- architecture behav of state_circuit is type state is ( AA, BB , CC , DD ) ; signal pr_state, nx_state : state ; signal rate , rt : integer ; begin process(pr_state , key) begin case pr_state is when AA=> outp <= '1' ; if(key(1)='0') then nx_state <= BB; elsif(key(2)='0') then nx_state <= CC; else nx_state <= DD; end if; rate<=16; when BB=> ------trang thai tang outp <= '1' ; if(key(1)='0') then nx_state <= BB; elsif(key(2)='0') then nx_state <= CC; else nx_state <= DD; END IF; if(rt<128) then rate<=rt*2; else rate<=rt; end if; when CC=> -------trang thai giam outp <= '1' ; if(key(1)='0') then nx_state<= BB; elsif(key(2)='0') then nx_state <= CC; ELSE nx_state <= DD; end if; if(rt>1) then rate<=rt/2; else rate<=rt; end if; when DD=> -------trang thai giam outp <= '1' ; if(key(1)='0') then nx_state <= BB; elsif(key(2)='0') then nx_state <= CC; ELSE nx_state <= DD; end if; RATE<=RT; end case ; end process; process( key,clk1 ) begin if(key(0)='0') then pr_state <=AA; elsif(clk1'event and clk1='1') then pr_state <= nx_state; RT<=rate; end if; end process; end behav;
Comment