-- The Electronic Gardener -- -- Mark Kudryk, Kim Ellis -- -- Module Name: maintain.vhd -- Author: Kim Ellis -- Date: November 07, 1998 -- Status: Completed ------------------------------------------------------------------------------- -- Description: -- Compare the real values to the set levels and Control the watering device. -- If the real value is below the set level, the device is -- turned on for a set amount of time, then shut off for same amount of time -- before testing the levels again. -- (this is to prevent overwatering) --------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; entity maintain is port( clk : in std_logic; reset : in std_logic; real_moist : in std_logic_vector( 7 downto 0 ); var_moist : in std_logic_vector( 7 downto 0 ); timer_moist : out std_logic; timeout_moist : in std_logic; over_moist : out std_logic; water_status : out std_logic; valve_on : buffer std_logic ); end maintain; architecture behaviour of maintain is signal sel : std_logic; begin process(reset, clk) begin if reset = '1' then valve_on <= '0'; water_status <= '0'; over_moist <= '0'; timer_moist <= '0'; sel <= '0'; elsif rising_edge(clk) then if sel='1' then if var_moist = "00000000" then -- if var_moist=0, keep everything off valve_on <= '0'; water_status <= '0'; timer_moist <= '0'; over_moist <= '0'; else if timeout_moist = '1' and valve_on = '0' then -- timer timeout & valve is off if real_moist < var_moist then valve_on <= '1'; -- turn water valve on water_status <= '1'; timer_moist <= '1'; --start timer for valve on over_moist <= '0'; else water_status <= '0'; -- not watering, higher real valve over_moist <= '1'; end if; elsif timeout_moist = '1' and valve_on = '1' then --timer timeout & valve is off valve_on <= '0'; --turn valve off water_status <= '1'; --still within one cycle timer_moist <= '1'; --start timer for valve off elsif timeout_moist = '0' then timer_moist <= '0'; --turn timer signal off while timer is counting end if; end if; --end if var=0 sel <= '0'; else sel<='1'; end if; --end sel if end if; --end reset/clk if end process; end behaviour;