Anda di halaman 1dari 2

--using textio.

all Entity Soda_Machine is port( --would need maximum of 30 nickles NICKEL_IN : std_logic_vector(4 downto 0); --would need maximum of 15 dimes DIME_IN : std_logic_vector(3 downto 0); --would need maxium of 6 quarters QUARTER_IN: std_logic_vector(2 downto 0); SELECTION: std_logic_vector(15 downto 0); PRICE: out std_logic_vector(15 downto 0); RESET: BOOLEAN; CLK: BIT; --return change and soda NICKEL_OUT, DIME_OUT, DISPENSE: out BOOLEAN ); End Soda_Machine; architecture BEHAVIOR of Soda_Machine is signal Current_Coin_Count, Next_Coin_Count: INTEGER range 0 to 30; -- 30 nickles is $1.50 signal Current_Return_Change, Next_Return_Change : BOOLEAN; begin process(NICKEL_IN, DIME_IN, QUARTER_IN, RESET, CLK, Current_Coin_Count, Current_Return_Change) --maximum amount of coins --possible is 30 niickles variable Temp_Coin_Count: INTEGER range 0 to 30; begin -- Set all Change Returned to 0 NICKEL_OUT <= FALSE; DIME_OUT <= FALSE; DISPENSE <= FALSE; Next_Coin_Count <= 0; NEXT_Return_Change <= FALSE; -- Synchronous reset if (not RESET) then Temp_Coin_Count := Current_Coin_Count; Case SELECTION is when "000" => PRICE := "110010"; End Case; -- Check whether change was put in the Machine if (NICKEL_IN) then Temp_Coin_Count := Temp_Coin_Count + 1; --counting number of nickles inputed elsif(DIME_IN) then Temp_Coin_Count := Temp_Coin_Count + 2; --counting number of dimes inputed elsif(QUARTER_IN) then Temp_Coin_Count := Temp_Coin_Count + 5; --counting number of quarters inputed end if; -- Keeps track if enough change was put in machine

--Macine Requires 25 Nickles if(Temp_Coin_Count >= 25) then Temp_Coin_Count := Temp_Coin_Count - 25; --soda given to customer DISPENSE <= TRUE; end if; --If too many nickles change is returned if(Temp_Coin_Count >= 1 or Current_Return_Change) then if(Temp_Coin_Count >= 2) then --dime returned DIME_OUT <= TRUE; Temp_Coin_Count := Temp_Coin_Count - 2; --stil return more change Next_Return_Change <= TRUE; end if; if(Temp_Coin_Count = 1) then --nickle returned NICKEL_OUT <= TRUE; Temp_Coin_Count := Temp_Coin_Count - 1; end if; end if; Next_Coin_Count <= Temp_Coin_Count; end if; end process; process begin --returns change on positive clock edege wait until CLK' event and CLK = '1'; Current_Return_Change <= NEXT_Return_Change; Current_Coin_Count <= Next_Coin_Count; end process; end BEHAVIOR;

Anda mungkin juga menyukai