I am trying to implement a vhdl vending machine. I have vectors to keep track of the coins. But this is not my main concern.
What I want to be able to do is give the user multiple choices of items all with varying prices. I then want the program to detect how many and what type of coin (nickel,dime,quarter) was put in the machine, until the price or greater is reached. It will then calculate how much money to return.
So what I need help with is the Case selection part of the code below. I need help writing a function so that it is clean.
What I want to be able to do is give the user multiple choices of items all with varying prices. I then want the program to detect how many and what type of coin (nickel,dime,quarter) was put in the machine, until the price or greater is reached. It will then calculate how much money to return.
So what I need help with is the Case selection part of the code below. I need help writing a function so that it is clean.
Rich (BB code):
--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;