2015-02-23 99 views
1

我是一個完整的VHDL初學者,所以我希望有人能幫助我完成這個項目。VHDL 8位計數器

我需要實現矩形脈衝發生器,其頻率可以在0到255範圍內變化。頻率值(kHz)必須在開發板上的8個LED二極管上顯示爲二進制。爲了調整輸出脈衝頻率,使用兩個按鈕(遞增/遞減)。當按鈕按下一秒以上時,頻率會自動遞增/遞減。

我寫了一些代碼,但在賽靈思中,我收到了很多警告。有人可以向我解釋他們嗎?

代碼分頻器:

-- Frequency divider 
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.NUMERIC_STD.ALL; 


entity frequency_divider_15Hz is 
port(
    cin : in std_logic; 
    CLK : out std_logic 
); 
end frequency_divider_15Hz; 


architecture behav_div of frequency_divider_15Hz is 
    signal tmp : integer := 0; 
    begin 
process(cin) 
    begin 
    if (cin'event and cin = '1') then 
     if (tmp < 800000) then 
       CLK <= '1'; 
       tmp <= tmp + 1; 
     elsif (tmp < 1600000) then 
       CLK <= '0'; 
       tmp <= tmp + 1; 
     else 
       CLK <= '0'; 
       tmp <= 0; 
     end if; 
    end if; 
end process; 
end behav_div; 

代碼狀態機:

-- State Machine 
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.NUMERIC_STD.ALL; 
entity state_machine is 
Port(
    CLK : in std_logic; 
    RESET : in std_logic; 
    U_D : in std_logic_vector (1 downto 0); 
    frequency_output : out std_logic_vector (7 downto 0)); 
end state_machine; 

architecture Behavioral of state_machine is 
signal number : unsigned(7 downto 0) := "00000001"; 
signal direction : std_logic; 
type state is (increment, decrement, restart, beginning, automatic); 
signal next_state : state := beginning; 
signal current_state : state := beginning; 
signal counter1 : integer := 0; 
signal counter2 : integer := 0; 
begin 

process (CLK) 
begin 
    if (CLK'event and CLK='1')then 
     frequency_output <= std_logic_vector(number); 
     case current_state is 
      when increment => 
       if (number < "11111111") then 
        number <= number + 1; 
       end if; 
      when decrement => 
       if (number > "00000001") then 
        number <= number - 1; 
       end if; 
      when restart => 
       number <= "00000001"; 
      when automatic => 
       if (direction='1') then 
        if (number <"11111111") then 
         number <= number + 1; 
        end if; 
        elsif (direction = '0') then 
         if (number > "00000001") then 
          number <= number - 1; 
         end if; 
       end if; 
      when others => 
        number <= number; 
     end case; 
     current_state <= next_state; 
    end if; 
end process; 


process (current_state, U_D,RESET, CLK) 
    begin 
    case current_state is 
      when beginning => 
        if (reset = '0') then 
         counter1 <= 0; 
         counter2 <= 0; 
         next_state <= restart; 
        elsif (CLK'event and CLK = '1') then 
         case U_D is 
          when "01" => 
            counter2 <= counter2 + 1; 
            next_state <= beginning; 
          when "10" => 
            counter1 <= counter1 + 1; 
            next_state <= beginning; 
          when "11" => 
           if (counter2 > 0) then 
            if (counter2 < 15) then 
             counter2 <= 0; 
             next_state <= increment; 
            else 
             direction <= '1'; 
             counter2 <= 0; 
             next_state <= automatic; 
            end if; 
           elsif (counter1>0) then 
            if (counter1 < 15) then 
             counter1 <= 0; 
             next_state <= decrement; 
            else 
             direction <= '0'; 
             counter1 <= 0; 
             next_state <= automatic; 
            end if; 
           else 
             counter1 <= 0; 
             counter2 <= 0; 
             next_state <= beginning; 
           end if; 
          when others => 
            next_state <= beginning; 
         end case; 
        end if; 
      when automatic => 
       if (reset = '0') then 
        next_state <= restart; 
       elsif (U_D(0) = '0') then 
        next_state <= beginning; 
       elsif (U_D(1) = '0') then 
        next_state <= beginning; 
       else 
        next_state <= automatic; 
       end if; 
      when increment => 
       next_state <= beginning; 
      when decrement => 
       next_state <= beginning; 
      when restart => 
       if (reset = '0') then 
        next_state <= restart; 
       else 
        next_state <= beginning; 
       end if; 
      when others => 
       next_state <= beginning; 
     end case; 
end process; 

end Behavioral; 

警告:

WARNING:Xst:737 - Found 1-bit latch for signal <counter1<31>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<30>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<29>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<28>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<27>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<26>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<25>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<24>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<23>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<22>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<21>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<20>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<19>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<18>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<17>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<16>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<15>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<14>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<13>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<12>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<11>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<10>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<9>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<8>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<7>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<6>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<5>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<4>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<3>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<2>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<1>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter1<0>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<31>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<30>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<29>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<28>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<27>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<26>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<25>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<24>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<23>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<22>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<21>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<20>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<19>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<18>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<17>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<16>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<15>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<14>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<13>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<12>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<11>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<10>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<9>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<8>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<7>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<6>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<5>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<4>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<3>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<2>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<1>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <counter2<0>>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 
WARNING:Xst:737 - Found 1-bit latch for signal <direction>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems. 

預先感謝。

+0

你有一個時鐘進程和一個非時鐘進程。警告可能與未超時的進程有關...... – 2015-02-23 20:10:09

+0

最近有一個問題有同樣的問題,但我似乎無法找到它。你不能在程序中的其他邏輯中嵌入代碼的時鐘部分(即在你的「開始」狀態) - 這不是合法的合成風格。可能還有其他問題。 – fru1tbat 2015-02-23 20:41:35

+0

frequency_output上有一組寄存器,您可能並不打算或不需要這些寄存器,它們是在鍾控過程中發生的編號分配。 – user1155120 2015-02-23 22:43:15

回答

2

你的狀態機的第二個過程是罪魁禍首。一個過程應該是同步的或組合的,而不是兩者的混合。

一種同步方法具有以下形式:

process(reset, clk) 
begin 
    if (reset = '0' then 
     signals <= reset_value; 
    elsif (clk'event and clk = '1') then 
     *logic here* 
    end if; 
end process; 

合流處理使用重置或CLK。當使用組合過程時,確保所有信號都分配在每個路徑中,即每個如果有其他的,每個情況都是其他的。未能在其中一個路徑中分配信號將產生鎖存。

鎖存器對除專家之外的任何人都是邪惡的化身。任何使用鎖存器的設計在硬件上的表現與在模擬上的表現並不相同。

+0

您提出的流程示例不同步,因爲它使用異步復位... – Paebbels 2015-02-23 21:53:55

+2

這有點麻煩。具有異步復位的寄存器仍然是一個同步元件。 – fru1tbat 2015-02-24 12:30:21