library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity CONTROLLORE is port ( CLK : in std_logic; RESET : in std_logic; START : in std_logic; TARGET_TEMP_GIORNO : in unsigned(7 downto 0); TARGET_TEMP_NOTTE : in unsigned(7 downto 0); ORA_INIZIO_GIORNO : in unsigned(4 downto 0); ORA_INIZIO_NOTTE : in unsigned(4 downto 0); INTERNAL_TEMP : in unsigned(7 downto 0); ORA : in unsigned(4 downto 0); SCALDA : out std_logic; PORTATA : out unsigned(5 downto 0) ); end CONTROLLORE ; architecture A of CONTROLLORE is type state is (idle, leggi, conta); signal present_state, next_state : state; signal enable, campiona : std_logic; signal fineciclo : std_logic; signal scalda_en : std_logic; signal scalda_in,scalda_ck : std_logic; signal current_cycle, next_cycle: unsigned(19 downto 0); signal target_giorno_ck, target_notte_ck : unsigned(7 downto 0); signal ora_ck, ora_giorno_ck, ora_notte_ck : unsigned(4 downto 0); signal giorno : std_logic; signal differenza : unsigned(7 downto 0); signal internal_ck: unsigned(7 downto 0); signal media : unsigned (5 downto 0); begin -- parte sequenziale della FSM process(clk) begin if clk'event and clk = '1' then if reset = '1' then present_state <= idle; else present_state <= next_state; end if; end if; end process; -- processo combinatorio, calcolo uscite e stato successivo process(present_state, START, fineciclo, media) begin enable <= '0'; campiona <= '0'; scalda_en <= '0'; --- case present_state is when idle => if START = '1' then next_state <= leggi; else next_state <= idle; end if; when leggi => campiona <= '1'; next_state <= conta; when conta => enable <= '1'; SCALDA_en <= '1' ; if fineciclo = '0' then next_state <= conta; else next_state <= leggi; end if; when others => next_state <= idle; end case; end process; -- contatore a 20 bit process(clk) begin if clk'event and clk = '1' then if reset = '1' or fineciclo = '1' then current_cycle <= conv_unsigned(0,20); elsif enable = '1' then current_cycle <= next_cycle; end if; end if; end process; -- valore successivo di conteggio next_cycle <= current_cycle + conv_unsigned(1,20); -- ultimo ciclo di lettura fineciclo <= '1' when current_cycle = conv_unsigned(9,14) else '0'; -- 599999 -- registri in cui memorizzo i dati di programmazione; vengono ---- abilitato da campiona process(clk) begin if clk'event and clk = '1' then if reset = '1' then target_giorno_ck <= conv_unsigned(0,8); elsif campiona = '1' then target_giorno_ck <= target_temp_giorno; end if; end if; end process; process(clk) begin if clk'event and clk = '1' then if reset = '1' then target_notte_ck <= conv_unsigned(0,8); elsif campiona = '1' then target_notte_ck <= target_temp_notte; end if; end if; end process; process(clk) begin if clk'event and clk = '1' then if reset = '1' then internal_ck <= conv_unsigned(0,8); elsif campiona= '1' then internal_ck <= internal_temp; end if; end if; end process; process(clk) begin if clk'event and clk = '1' then if reset = '1' then ora_ck <= conv_unsigned(0,5); elsif campiona= '1' then ora_ck <= ora; end if; end if; end process; process(clk) begin if clk'event and clk = '1' then if reset = '1' then ora_giorno_ck <= conv_unsigned(0,5); elsif campiona= '1' then ora_giorno_ck <= ora_inizio_giorno; end if; end if; end process; process(clk) begin if clk'event and clk = '1' then if reset = '1' then ora_notte_ck <= conv_unsigned(0,5); elsif campiona= '1' then ora_notte_ck <= ora_inizio_notte; end if; end if; end process; ---- per gestire scalda process(clk) begin if clk'event and clk = '1' then if reset = '1' then scalda_ck <= '0'; elsif scalda_en= '1' then scalda_ck <= scalda_in; end if; end if; end process; -- scalda_in <= '1' when (target_giorno_ck > internal_ck) else '0'; scalda <= scalda_ck; ---- elaborazione combinatoria giorno <= '1' when (ORA_CK >= ORA_GIORNO_CK and ORA_CK < ORA_NOTTE_CK) else '0'; --differenza <= target_giorno_ck-internal_ck when (target_giorno_ck > internal_ck) else "00000000" ; -- mux per definire differenza process(giorno, target_giorno_ck, target_notte_ck, internal_ck) begin case giorno is when '1' => if target_giorno_ck > internal_ck then differenza <= target_giorno_ck-internal_ck ; scalda_in <= '1'; else differenza <= "00000000"; scalda_in <= '0'; end if; when '0' => if target_notte_ck > internal_ck then differenza <= target_notte_ck-internal_ck ; scalda_in <= '1'; else differenza <= "00000000"; scalda_in <= '0'; end if; when others => differenza <= "00000000"; end case; end process; media <=differenza(7 downto 2); PORTATA <= media; end A;