VHDL状态机:如何使currenttempinc信号递减

时间:2017-03-25 23:25:01

标签: vhdl counter decrement

如何使我的currenttempinc信号减少。到目前为止,我只能将currenttempinc信号递增。这就是我尝试递减信号currenttempdec< = currenttempdec - 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; 

            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; 

1 个答案:

答案 0 :(得分:0)

我修好了。我认为问题出在各州。

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;