【问题标题】:VHDL state machine: how to make currenttempinc signal decrementVHDL状态机:如何使currenttempinc信号递减
【发布时间】:2017-03-25 23:25:01
【问题描述】:

如何使我的 currenttempinc 信号递减。到目前为止,我只能让 currenttempinc 信号增加。这就是我试图减少信号 currenttempdec

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; 

【问题讨论】:

  • 如果在错误的地方结束。
  • 如果我应该把结尾移到这里吗?
  • 这样吗? currenttempinc
  • 正确格式化您的代码,您应该会看到它。
  • 依然不会递减。

标签: vhdl counter decrement


【解决方案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; 

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    相关资源
    最近更新 更多