Paolin

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

https://prezi.

com/0adveyqyhdli/maquina-expendedora-productos-veraniegos/
https://es.wikipedia.org/wiki/Encaminamiento#Algoritmos_por_.E2.80.9Cvector_de_d
istancias.E2.80.9D
--------------------------------------------------------------------------------
--
-- Company:
-- Engineer:
--
-- Create Date: 18:18:19 10/12/2015
-- Design Name:
-- Module Name: Cola_Machine - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
--------------------------------------------------------------------------------
--
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.all;
entity Cola_Machine is
port( clk : in STD_LOGIC;
reset : in STD_LOGIC;
On_Off_Button : in STD_LOGIC;
Products_Inputs : in STD_LOGIC_VECTOR(1 downto 0);
ProductsSensor_One : in STD_LOGIC_VECTOR(3 downto 0);
ProductsSensor_Two : in STD_LOGIC_VECTOR(3 downto 0);
Motors : out STD_LOGIC_VECTOR(4 downto 0);
Charge_Sensor : in STD_LOGIC_VECTOR(6 downto 0);
StoredMoney_Sensor : inout STD_LOGIC_VECTOR(6 downto 0);
Temperature_Sensor : in STD_LOGIC_VECTOR(5 downto 0);
LCD_Display : out STD_LOGIC_VECTOR(7 downto 0);
Operational_Sensor: in STD_LOGIC
);

end Cola_Machine;
architecture Behavioral of Cola_Machine is
type state_type is (TurnOn, Charge, Search, Give, Pay, Sleep, TurnOff);
signal state, next_state : state_type;
constant SetTemperatureValue : integer := 23;
constant Soda_OrangeCost : integer := 10;
constant Soda_ColeCost : integer := 12;
alias Fridge : STD_LOGIC is Motors(0);
alias Take_Bills : STD_LOGIC is Motors(1);
alias Give_Change : STD_LOGIC is Motors(2);
alias Soda_Orange : STD_LOGIC is Motors(3);
alias Soda_Cole : STD_LOGIC is Motors(4);
begin
SYNC_PROC: process (clk)
begin
if (clk'event and clk = '1') then
if (reset = '1') then
state <= TurnOn;
else
state <= next_state;
end if;
end if;
end process;
--MEALY State-Machine - Outputs based on state and inputs
OUTPUT_DECODE: process (state, Temperature_Sensor, Charge_Sensor)
begin
end process;
NEXT_STATE_DECODE: process (state)
variable TempTemperature : integer := 0;
variable TempCharge: integer := 0;
variable MoneyOnTheMachine : integer := 0;
variable ProductsOneStored : integer := 0;
variable ProductsTwoStored : integer := 0;
variable SelectedItem : integer := 0;
begin
next_state <= state;
case (state) is
when TurnOn =>
if On_Off_Button = '1' then
next_state <= TurnOff;
end if;
-- Gets the initial temperature.
TempTemperature := CONV_INTEGER(Temperature_Sens
or);
-- If the temperature read is bigger than the pr
oduct default temperature, turn on the fridge motor.
if TempTemperature > SetTemperatureValue then
Fridge <= '1';
else
-- All motors on hold until the machine
change its state.
Motors <= (Others => '0');
end if;
-- The initial display must be set to the initia
lization state.
LCD_Display <= (others => '0');
-- Gets the initial money value stored on the ma
chine.
MoneyOnTheMachine := CONV_INTEGER(StoredMoney_Se
nsor);
TempCharge := 0;
-- Gets the number of products stored
ProductsOneStored := CONV_INTEGER(ProductsSensor
_One);
ProductsTwoStored := CONV_INTEGER(ProductsSensor
_Two);
-- When the machine gets money from the client
if TempCharge /= 0 then
next_state <= Charge;
else
next_state <= Sleep;
end if;
when Charge =>
if Operational_Sensor = '1' then
Take_Bills <= '1';
else
Take_Bills <= '0';
end if;
-- Get the real among of money insert by the cli
ent and check if more money was inserted.
if TempCharge = TempCharge + CONV_INTEGER(Charge
_Sensor) then
next_state <= Search;
else
-- Hold on
TempCharge := TempCharge + CONV_INTEGER(
Charge_Sensor);
LCD_Display <= CONV_STD_LOGIC_VECTOR(Tem
pCharge,8);
Motors <= (Others => '0');
next_state <= Charge;
end if;
LCD_Display <= CONV_STD_LOGIC_VECTOR(TempCharge,
8);
when Search =>
if Products_Inputs(0) = '1' and ProductsOneStore
d > 0 then
if TempCharge >= Soda_OrangeCost and Mon
eyOnTheMachine >= TempCharge - Soda_OrangeCost then
SelectedItem := 1;
LCD_Display <= CONV_STD_LOGIC_VE
CTOR(Soda_OrangeCost,8);
next_state <= Give;
end if;
elsif Products_Inputs(1) = '1' and ProductsTwoSt
ored > 0 then
if TempCharge >= Soda_ColeCost and Money
OnTheMachine >= TempCharge - Soda_ColeCost then
SelectedItem := 2;
LCD_Display <= CONV_STD_LOGIC_VE
CTOR(Soda_ColeCost,8);
next_state <= Give;
end if;
else
SelectedItem := 0;
next_state <= Pay;
end if;
when Give =>
case SelectedItem is
when 1 =>
Soda_Orange <= '1';
if ProductsOneStored /= CONV_INT
EGER(ProductsSensor_One) then
ProductsOneStored := CON
V_INTEGER(ProductsSensor_One);
next_state <= Sleep;
else
next_state <= Pay;
end if;
when 2 =>
Soda_Cole <= '1';
if ProductsTwoStored /= CONV_INT
EGER(ProductsSensor_Two) then
ProductsTwoStored := CON
V_INTEGER(ProductsSensor_Two);
next_state <= Sleep;
else
next_state <= Pay;
end if;
when others =>
next_state <= Pay;
end case;
when Pay =>
case SelectedItem is
when 0 =>
LCD_Display <= CONV_STD_LOGIC_VE
CTOR(TempCharge,8);
StoredMoney_Sensor <= CONV_STD_L
OGIC_VECTOR(TempCharge,7);
Give_Change <= '1';
when 1 =>
MoneyOnTheMachine := MoneyOnTheM
achine + Soda_OrangeCost;
TempCharge := TempCharge - Soda_
OrangeCost;
StoredMoney_Sensor <= CONV_STD_L
OGIC_VECTOR(TempCharge,7);
LCD_Display <= '0' & StoredMoney
_Sensor;
Give_Change <= '1';
next_state <= Sleep;
when 2 =>
MoneyOnTheMachine := MoneyOnTheM
achine + Soda_ColeCost;
TempCharge := TempCharge - Soda_
OrangeCost;
StoredMoney_Sensor <= CONV_STD_L
OGIC_VECTOR(TempCharge,7);
LCD_Display <= '0' & StoredMoney
_Sensor;
Give_Change <= '1';
next_state <= Sleep;
when others =>
next_state <= Sleep;
end case;
if On_Off_Button = '1' then
next_state <= TurnOff;
end if;

when Sleep =>


-- If the machine should wake up because the cli
ent insert money on the machine.
if Operational_Sensor = '1' and TempCharge /= Ch
arge_Sensor then
next_state <= Charge;
-- If the machine should wake up because the pro
duct are getting hot and could be damage.
elsif Operational_Sensor = '1' and TempTemperatu
re /= Temperature_Sensor then
next_state <= TurnOn;
else
Motors <= (Others => '0');
end if;
if On_Off_Button = '1' then
next_state <= TurnOff;
end if;
when TurnOff =>
LCD_Display <= (others => '0');
Motors <= (Others => '0');
when others =>
end case;
end process;
end Behavioral;

You might also like