-- The Electronic Gardener -- -- Mark Kudryk, Kim Ellis -- -- Module Name: session.vhd -- Author: Kim Ellis -- Date: November 07, 1998 -- Status: Completed ---------------------------------------------------------------- -- Description: -- Determine the state of the watering session, -- then compare the set start/stop times to the 24-hour clock -- and Control the watering device -- If the start time is equal to the 24-hour clock, -- the device is turned on until the end time is reached ---------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity session is port( clk : in std_logic; reset : in std_logic; hour : in std_logic_vector( 7 downto 0 ); minute : in std_logic_vector( 7 downto 0 ); water_session : in std_logic; moist_start_h : in std_logic_vector( 7 downto 0 ); moist_start_m : in std_logic_vector( 7 downto 0 ); moist_end_h : in std_logic_vector( 7 downto 0 ); moist_end_m : in std_logic_vector( 7 downto 0 ); water_status : out std_logic; valve_on : buffer std_logic ); end session; architecture behaviour of session is begin process(reset, clk) begin if reset = '1' then valve_on <= '0'; water_status <= '0'; elsif rising_edge(clk) then --water if water_session = '1' then if moist_end_h < moist_start_h then --change in hour if moist_end_m < moist_start_m then --change in minutes if hour >= moist_start_h and minute >= moist_start_m then valve_on <= '1'; --turn on the water valve water_status <= '1'; elsif hour <= moist_end_h and minute < moist_end_m then valve_on <= '1'; --turn on the water valve water_status <= '1'; else valve_on <= '0'; --turn valve off water_status <= '0'; end if; end if; else if moist_end_m < moist_start_m then --change in minutes, no change in hour if hour >= moist_start_h and minute >= moist_start_m then valve_on <= '1'; --turn on the water valve water_status <= '1'; elsif hour <= moist_end_h and minute < moist_end_m then valve_on <= '1'; --turn on water valve water_status <= '1'; else valve_on <= '0'; --turn valve on water_status <= '0'; end if; else --no change in minutes & hour if hour >= moist_start_h and minute >= moist_start_m and hour <= moist_end_h and minute <= moist_end_m - 1 then valve_on <= '1'; --turn on water valve water_status <= '1'; else valve_on <= '0'; --turn valve off water_status <= '0'; end if; end if; end if; else valve_on <= '0'; --turn valve off water_status <= '0'; end if; end if; end process; end behaviour;