Commit dfe17c80 authored by Rashed Al-Lahaseh's avatar Rashed Al-Lahaseh
Browse files

Add laundry fsm entiy

Laundry FSM Entity
parent 83d52b6a
library ieee;
use ieee.std_logic_1164.all;
entity e_laundry_fsm is
generic(n:integer:= 8);
port(
CLOCK_50, reset: in std_logic;
nearby_person_sensor, washing_machine_done_sensor: in std_logic;
push_password_button, push_address_button: in std_logic;
washing_machine_available, paid: in boolean;
password_in, washing_machine_address_in: in std_logic_vector(n-5 downto 0);
working_washing_machines_count: out integer range 0 to 9;
state_choice: out integer range 0 to 9
);
end e_laundry_fsm;
architecture a_laundry_fsm of e_laundry_fsm is
constant c_password: std_logic_vector(3 downto 0) := "0000";
constant c_laundry_room_capacity: integer := 9;
type laundry_states is (no_action_state, user_detect_state, verification_state,
availability_state, payment_state, process_state,
finished_processing_state, full_state, hold_state,
start_state);
signal sl_present_state: laundry_states := no_action_state;
signal sl_password_button_last_state: std_logic := '0';
signal sl_address_button_last_state: std_logic := '0';
signal sl_used_washing_machines_count: integer range 0 to 9 := 0;
signal sl_state_choice: integer range 0 to 9;
------------------------------------- architecture begins -------------------------------------
begin
process(CLOCK_50, reset, nearby_person_sensor, push_password_button, push_address_button)
begin
if(reset = '0') then -- active low reset
sl_present_state <= no_action_state;
elsif(rising_edge(CLOCK_50)) then
case sl_present_state is
when no_action_state =>
if(nearby_person_sensor = '1') then
sl_present_state <= user_detect_state;
else
sl_present_state <= no_action_state;
end if;
when user_detect_state =>
-- the user has to enter the password through the 4 switches and pushes the button
if(push_password_button='1' and sl_password_button_last_state = '0') then -- push button pushed
if(password_in = c_password) then -- correct password => change state
sl_present_state <= verification_state;
end if;
else
sl_present_state <= user_detect_state;
end if;
sl_password_button_last_state <= push_password_button; -- debouncing the push button
when verification_state =>
if(push_address_button = '1' and sl_address_button_last_state = '0') then -- push button pushed
sl_present_state <= availability_state;
else
sl_present_state <= verification_state;
end if;
sl_address_button_last_state <= push_address_button; -- debouncing the push button
when availability_state =>
if(washing_machine_available) then -- checking if the place is available
sl_present_state <= payment_state;
end if;
when payment_state =>
if(paid) then
sl_present_state <= process_state;
else
sl_present_state <= payment_state;
end if;
when process_state =>
-- checking if the washing machine finished the work
if(washing_machine_done_sensor = '0') then
sl_present_state <= finished_processing_state;
else -- still did not finished => HOLD
sl_present_state <= hold_state;
end if;
when finished_processing_state =>
if(washing_machine_done_sensor = '0') then
sl_present_state <= start_state;
end if;
when hold_state =>
if(washing_machine_done_sensor ='0') then
sl_present_state <= process_state;
else
sl_present_state <= hold_state;
end if;
when start_state =>
-- increment the count of used washing machines
sl_used_washing_machines_count <= sl_used_washing_machines_count + 1;
if(sl_used_washing_machines_count = c_laundry_room_capacity) then -- full park
sl_present_state <= full_state;
else
sl_present_state <= no_action_state; -- full loop
end if;
when full_state =>
sl_present_state <= full_state; -- deadlock will happen
end case;
end if;
end process;
working_washing_machines_count <= sl_used_washing_machines_count;
with sl_present_state select
sl_state_choice <= 0 when no_action_state,
1 when user_detect_state,
2 when verification_state,
3 when availability_state,
4 when payment_state,
5 when process_state,
6 when finished_processing_state,
7 when hold_state,
8 when start_state,
9 when full_state;
end a_laundry_fsm;
\ No newline at end of file
library ieee;
use ieee.std_logic_1164.all;
entity e_payment_fsm is
generic(n:integer:= 16);
port(
coin_in: in std_logic_vector(n-13 downto 0); -- "1 Euro, 50cents, 20cents, 10cents" -- "1111"
coin_out: out std_logic_vector(n-13 downto 0); -- "1 Euro, 50cents, 20cents, 10cents" -- "1111"
payment: out integer range 0 to 290;
paid: out boolean
);
end e_payment_fsm;
architecture a_payment_fsm of e_payment_fsm is
type payment_states is (zero_cent, ten_cents, twenty_cents, thirty_cents, fourty_cents, fifty_cents, sixty_cents,
seventy_cents, eighty_cents, ninety_cents, one_euro, one_euro_ten_cents,
one_euro_twenty_cents, one_euro_thirty_cents, one_euro_fourty_cents, one_euro_fifty_cents, one_euro_sixty_cents,
one_euro_seventy_cents, one_euro_eighty_cents, one_euro_ninty_cents,two_euro, two_euro_ten_cents, two_euro_twenty_cents,
two_euro_thirty_cents, two_euro_fourty_cents, two_euro_fifty_cents, two_euro_sixty_cents, two_euro_seventy_cents,
two_euro_eighty_cents, two_euro_ninty_cents);
signal sl_coin_state: payment_states := zero_cent;
------------------------------------- architecture begins -------------------------------------
begin
process(coin_in) begin
case sl_coin_state is
when zero_cent =>
if (coin_in = "0001") then sl_coin_state <= ten_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= twenty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= fifty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro; --+100
else sl_coin_state <= zero_cent;-- +0
end if;
coin_out <= "0000";
payment <= 0;
when ten_cents =>
if (coin_in = "0001") then sl_coin_state <= twenty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= thirty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= sixty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_ten_cents; --+100
else sl_coin_state <= ten_cents;-- +0
end if;
coin_out <= "0000";
payment <= 10;
when twenty_cents =>
if (coin_in = "0001") then sl_coin_state <= thirty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= fourty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= seventy_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_twenty_cents; --+100
else sl_coin_state <= twenty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 20;
when thirty_cents =>
if (coin_in = "0001") then sl_coin_state <= fourty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= fifty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= eighty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_thirty_cents; --+100
else sl_coin_state <= thirty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 30;
when fourty_cents =>
if (coin_in = "0001") then sl_coin_state <= fifty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= sixty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= ninety_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_fourty_cents; --+100
else sl_coin_state <= fourty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 40;
when fifty_cents =>
if (coin_in = "0001") then sl_coin_state <= sixty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= seventy_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_fifty_cents; --+100
else sl_coin_state <= fifty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 50;
when sixty_cents =>
if (coin_in = "0001") then sl_coin_state <= seventy_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= eighty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_ten_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_sixty_cents; --+100
else sl_coin_state <= sixty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 60;
when seventy_cents =>
if (coin_in = "0001") then sl_coin_state <= eighty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= ninety_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_twenty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_seventy_cents; --+100
else sl_coin_state <= seventy_cents;-- +0
end if;
coin_out <= "0000";
payment <= 70;
when eighty_cents =>
if (coin_in = "0001") then sl_coin_state <= ninety_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_thirty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_eighty_cents; --+100
else sl_coin_state <= eighty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 80;
when ninety_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_ten_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_fourty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= one_euro_ninty_cents; --+100
else sl_coin_state <= ninety_cents;-- +0
end if;
coin_out <= "0000";
payment <= 90;
when one_euro =>
if (coin_in = "0001") then sl_coin_state <= one_euro_ten_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_twenty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_fifty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro; --+100
else sl_coin_state <= one_euro;-- +0
end if;
coin_out <= "0000";
payment <= 100;
when one_euro_ten_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_twenty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_thirty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_sixty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_ten_cents; --+100
else sl_coin_state <= one_euro_ten_cents;-- +0
end if;
coin_out <= "0000";
payment <= 110;
when one_euro_twenty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_thirty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_fourty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_seventy_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_twenty_cents; --+100
else sl_coin_state <= one_euro_twenty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 120;
when one_euro_thirty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_fourty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_fifty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_eighty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_thirty_cents; --+100
else sl_coin_state <= one_euro_thirty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 130;
when one_euro_fourty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_fifty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_sixty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= one_euro_ninety_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_fourty_cents; --+100
else sl_coin_state <= one_euro_fourty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 140;
when one_euro_fifty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_sixty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_seventy_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= two_euro;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_fifty_cents; --+100
else sl_coin_state <= one_euro_fifty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 150;
when one_euro_sixty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_seventy_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_eighty_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= two_euro_ten_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_sixty_cents; --+100
else sl_coin_state <= one_euro_sixty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 160;
when one_euro_seventy_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_eighty_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= one_euro_ninety_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= two_euro_twenty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_seventy_cents; --+100
else sl_coin_state <= seventy_cents;-- +0
end if;
coin_out <= "0000";
payment <= 170;
when one_euro_eighty_cents =>
if (coin_in = "0001") then sl_coin_state <= one_euro_ninety_cents;-- +10
elsif(coin_in = "0010") then sl_coin_state <= two_euro;-- +20
elsif(coin_in = "0100") then sl_coin_state <= two_euro_thirty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_eighty_cents; --+100
else sl_coin_state <= one_euro_eighty_cents;-- +0
end if;
coin_out <= "0000";
payment <= 180;
when one_euro_ninety_cents =>
if (coin_in = "0001") then sl_coin_state <= two_euro;-- +10
elsif(coin_in = "0010") then sl_coin_state <= two_euro_ten_cents;-- +20
elsif(coin_in = "0100") then sl_coin_state <= two_euro_fourty_cents;-- +50
elsif(coin_in = "1000") then sl_coin_state <= two_euro_ninty_cents; --+100
else sl_coin_state <= one_euro_ninety_cents;-- +0
end if;
coin_out <= "0000";
payment <= 190;
when two_euro =>
coin_out <= "0000";
paid <= true;
payment <= 200;
when two_euro_ten_cents =>
coin_out <= "0001"; -- give back 10
paid <= true;
payment <= 210;
when two_euro_twenty_cents =>
coin_out <= "0010"; -- give back 20
paid <= true;
payment <= 220;
when two_euro_thirty_cents =>
coin_out <= "0011"; -- give back 10, 20
paid <= true;
payment <= 230;
when two_euro_fourty_cents =>
coin_out <= "0011"; -- give back 10, 20
sl_coin_state <= two_euro_ten_cents; -- to give back the remaining 10 cents
payment <= 240;
when two_euro_fifty_cents =>
coin_out <= "0100"; -- give back 50
paid <= true;
payment <= 250;
when two_euro_sixty_cents =>
coin_out <= "0101"; -- give back 50, 10
paid <= true;
payment <= 260;
when two_euro_seventy_cents =>
coin_out <= "0110"; -- give back 50, 20
paid <= true;
payment <= 270;
when two_euro_eighty_cents =>
coin_out <= "0111"; -- give back 50, 20, 10
paid <= true;
payment <= 280;
when two_euro_ninety_cents =>
coin_out <= "0111"; -- give back 50, 20, 10
sl_coin_state <= two_euro_ten_cents; -- to give back the remaining 10 cents
payment <= 290;
end case;
end process;
end architecture;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment