实验内容:
1. 设计一个自动售饮料机的控制逻辑电路。
该机器有一个投币口,每次只能投入1枚1元或5角的硬币。
当投入了1元5角的硬币,机器自动给出1杯饮料。当投入了2元的硬币,机器在自动给出1杯饮料时,还找回1枚5角的硬币。
确定输入/输出变量、电路的状态并化简,做出状态转换图、状态转换表。
2. 在完成以上逻辑设计后,用VHDL编程并仿真。
自动售饮料机的控制逻辑电路设计
取投币信号为输入逻辑变量:令A=1表示投入1枚一元硬币。B=1表示投入1枚五角硬币。
逻辑抽象 输出变量:Y=1表示给出一杯饮料。Z=1表示找回一枚五角的硬币。
输出: 所有的输出情况为
YZ = 00、YZ = 10、YZ = 11 。
系统框图:
输出饮料 输出找零
输入:当前投入的币值,
AB = 00、金额为0;
AB = 01、金额为5角;AB = 10、金额为1元。
输出:
设Z1 =1→ 输出饮料;
Z2 =1→输出找零。所有的输出情况为Z1Z2 = 00、Z1Z2 = 10、Z1Z2 = 11 。
分析:
输出饮料 输出找零
输入:当前投入的币值,
X1X2 = 00、金额为0;X1X2 = 01、金额为5角;X1X2 = 10、金额为1元。
状态分析
状态转换图
所有的输出情况:
Z1Z2 = 00
Z1Z2 = 10
Z1Z2 = 11
设未投币前电路的初始状态为S0,状态S1为已经投入五角硬币,状态S2为已经投入一元硬币。
状态转换表

1 library ieee; 2 use ieee.std_logic_1164.all; 3 entity sell_state is 4 port( clk , rst : in std_logic; 5 x : in std_logic_vector(1 downto 0); 6 y : out std_logic_vector(1 downto 0)); 7 end sell_state; 8 architecture behave of sell_state is 9 type states is (state0 , state1 , state2); 10 signal state : states; 11 begin 12 process(clk , rst , x) 13 begin 14 if rst = '1' then state <= state1; y <= "00"; 15 elsif (clk'event and clk = '1') then 16 case state is 17 when state0 => 18 if(x = "01") then state <= state1; y <= "00"; 19 elsif(x = "10") then state <= state2; y <= "00"; 20 else state <= state0; y <= "00"; 21 end if; 22 when state1 => 23 if(x = "10") then state <= state0; y <= "10"; --rst <= '1'; 24 elsif(x = "01") then state <= state2; y <= "00"; 25 else state <= state1; y <= "00"; 26 end if; 27 when state2 => 28 if(x = "10") then state <= state0; y <= "11"; --rst <= '1'; 29 elsif(x = "01") then state <= state0; y <= "10"; --rst <= '1'; 30 else state <= state2; y <= "00"; 31 end if; 32 end case; 33 end if; 34 end process; 35 end behave;