2017-03-25 16 views
-2

currenttempinc 신호 감소를 어떻게 만들 수 있습니까? 지금까지는 currenttempinc 신호 만 증가시킬 수있었습니다. 이것은 내가 currenttempdec 신호를 감소 시키려고 시도한 것입니다. < = currenttempdec - 1; 그러나 그의 코드 행은 심지어 읽히지 않는 것처럼 보입니다.VHDL 상태 머신 : currenttempinc 신호 감소 방법

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use ieee.std_logic_unsigned.all; 

entity question4 is 
Port (
--System Clock Declaration-------------------------- 
clk: in std_logic; 

--Button Inputs------------------------------------- 
btnU: in std_logic; --Clear 
btnD: in std_logic; --Reset 

sw: in std_logic_vector(15 downto 0); 
led: out std_logic_vector(15 downto 0) 
); 
end question4; 

architecture Behavioral of question4 is 

constant active: std_logic := '1'; 
constant bloweron: std_logic_vector(15 downto 0) := "0000000011111111"; 
constant compon: std_logic_vector(15 downto 0) := "1111111100000000"; 
constant blowonandcompon : std_logic_vector (15 downto 0) := "1111111111111111"; 
constant blowoffandcompoff: std_logic_vector (15 downto 0) := "0000000000000000"; 

signal clear: std_logic := btnU; 
signal reset: std_logic := btnD; 
signal settemp: std_logic_vector := sw(7 downto 0); 
signal temp_speed: std_logic; 
signal currenttempinc: std_logic_vector(7 downto 0); 
signal currenttempdec: std_logic_vector(7 downto 0):= "11111111"; 
signal start_current_tempup: std_logic := sw(15); 
signal start_current_tempdown: std_logic := sw(14); 

type states is (blowoncompoff, 
       blowoffcompoff, 
       blowoncompon); 

signal CurrentState: states; 
signal NextState: states; 

begin 

SpeedControl: process (clk, reset) 
        variable counter: integer range 0 to 100000000; 
       begin 
        temp_speed <= not active; 
        if Reset = Active then 
         counter:= 0; 
        elsif (rising_edge (clk)) then --addded 
         counter := counter + 1; 
         if (counter=100000000) then 
          temp_speed <= Active; 
          counter:=0; 
         end if; 
        end if; 
       end process; 

State_Register: process (clk, Reset) 
       begin 
        if Reset = active then 
         CurrentState <= blowoffcompoff; 
        elsif (rising_edge(clk)) then 
         CurrentState <= NextState;     
        end if; 
       end process; 

motorstatetrans: process(currentstate, currenttempinc, settemp, clear, temp_speed) 
begin 

    case currentstate is 

     when blowoncompon => 
      led <= blowonandcompon; 

      if temp_speed = active then 

       if currenttempinc=settemp then 
        Nextstate <= blowoncompoff; 

      elsif currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

      end if; 
     end if; 

     when blowoncompoff => 
      led <= bloweron; 

      if temp_speed = active then 

       if currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

       elsif currenttempinc > settemp then --changed from = to > 
        Nextstate <= blowoffcompoff; 

       else Nextstate <= blowoncompoff; 
      end if; 
      end if; 

     when blowoffcompoff => 

     led <=blowoffandcompoff; 

      if temp_speed = active then 

       if currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

       elsif currenttempinc > settemp or currenttempinc = settemp then 
        Nextstate <= blowoffcompoff; 
       end if; 
      end if; 
    end case; 
end process;  

current_temperature: process (reset,clear, clk) 
begin 
    if rising_edge (clk) then 
     if reset = active or clear = active then 
      currenttempinc <= "00000000"; 

     elsif temp_speed = active and start_current_tempup=active and start_current_tempdown = not active then 
      currenttempinc <= currenttempinc + 1 ; 
      if currenttempinc = "11111111" then 
       currenttempinc <= "00000000"; 
      end if; 
     elsif temp_speed = active and start_current_tempdown = active and start_current_tempup = not active then 
      currenttempinc <= currenttempinc - 1; 
      if currenttempinc = "00000000" then 
       currenttempinc <= "11111111"; 
      end if; 
     end if;  
    end if; 
end process; 

end behavioral; 
+0

끝 부분이 잘못된 위치에 있습니다. –

+0

끝 부분을 이동해야하는 경우이 위치에 있습니까? – cobra66

+0

이 마음에 드십니까? currenttempinc <= currenttempinc +1; currenttempinc = "11111111"이면 currenttempinc <= "00000000"; end if; – cobra66

답변

-1

해결했습니다. 나는 그 문제가 주에 있다고 생각한다.

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use ieee.std_logic_unsigned.all; 

entity question4 is 
Port (
--System Clock Declaration-------------------------- 
clk: in std_logic; 

--Button Inputs------------------------------------- 
btnU: in std_logic; --Clear 
btnD: in std_logic; --Reset 

sw: in std_logic_vector(15 downto 0); 
led: out std_logic_vector(15 downto 0) 
); 
end question4; 

architecture Behavioral of question4 is 

constant active: std_logic := '1'; 
constant bloweron: std_logic_vector(15 downto 0) := "0000000011111111"; 
constant compon: std_logic_vector(15 downto 0) := "1111111100000000"; 
constant blowonandcompon : std_logic_vector (15 downto 0) := "1111111111111111"; 
constant blowoffandcompoff: std_logic_vector (15 downto 0) := "0000000000000000"; 

signal clear: std_logic := btnU; 
signal reset: std_logic := btnD; 
signal settemp: std_logic_vector := sw(7 downto 0); 
signal temp_speed: std_logic; 
signal currenttempinc: std_logic_vector(7 downto 0); 
signal currenttempdec: std_logic_vector(7 downto 0):= "11111111"; 
signal start_current_tempup: std_logic := sw(15); 
signal start_current_tempdown: std_logic := sw(14); 

type states is (blowoncompoff, 
       blowoffcompoff, 
       blowoncompon); 

signal CurrentState: states; 
signal NextState: states; 

begin 

SpeedControl: process (clk, reset) 
        variable counter: integer range 0 to 100000000; 
       begin 
        temp_speed <= not active; 
        if Reset = Active then 
         counter:= 0; 
        elsif (rising_edge (clk)) then --addded 
         counter := counter + 1; 
         if (counter=100000000) then 
          temp_speed <= Active; 
          counter:=0; 
         end if; 
        end if; 
       end process; 

State_Register: process (clk, Reset) 
       begin 
        if Reset = active then 
         CurrentState <= blowoffcompoff; 
        elsif (rising_edge(clk)) then 
         CurrentState <= NextState;     
        end if; 
       end process; 

motorstatetrans: process(currentstate, currenttempinc, settemp, clear, temp_speed) 
begin 

    case currentstate is 

     when blowoncompon => 
      led <= blowonandcompon; 

      if temp_speed = active then 

       if currenttempinc=settemp then 
        Nextstate <= blowoncompoff; 

       elsif currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

       elsif currenttempinc > settemp then 
        Nextstate <= blowoffcompoff; 

      end if; 
     end if; 

     when blowoncompoff => 
      led <= bloweron; 

      if temp_speed = active then 

       if currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

       elsif currenttempinc > settemp then --changed from = to > 
        Nextstate <= blowoffcompoff; 

       else Nextstate <= blowoncompoff; 
      end if; 
      end if; 

     when blowoffcompoff => 

     led <=blowoffandcompoff; 

      if temp_speed = active then 

       if currenttempinc < settemp then 
        Nextstate <= blowoncompon; 

       elsif currenttempinc > settemp or currenttempinc = settemp then 
        Nextstate <= blowoffcompoff; 
       end if; 
      end if; 
    end case; 
end process;  

current_temperature: process (reset,clear, clk) 
begin 
    if rising_edge (clk) then 
     if reset = active or clear = active then 
      currenttempinc <= "00000000"; 

     elsif temp_speed = active and start_current_tempup=active and start_current_tempdown = not active then 
      currenttempinc <= currenttempinc + 1 ; 
      if currenttempinc = "11111111" then 
       currenttempinc <= "00000000"; 
      end if; 
     elsif temp_speed = active and start_current_tempdown = active and start_current_tempup = not active then 
      currenttempinc <= currenttempinc - 1; 
      if currenttempinc = "00000000" then 
       currenttempinc <= "11111111"; 
      end if; 
     end if;  
    end if; 
end process; 

end behavioral;