2014-12-22 40 views
0

我正在做一個音樂盒與VHDL。我第一次玩A4,而且我很成功。For循環和rom在vhdl

library IEEE; 

use IEEE.STD_LOGIC_1164.ALL; 

use IEEE.NUMERIC_STD.ALL; 


library UNISIM; 

use UNISIM.VComponents.all; 


entity Basic is 

    Port( clk : in STD_LOGIC; 
     note : out STD_LOGIC; 
     ); 
end Basic; 

architecture Behavioral of Basic is 

    signal count : unsigned (15 downto 0) := (others => '0'); 
begin 

    note <= std_logic(count(15)); 
    process (clk) 
    begin 
     if rising_edge(clk) then 
      if (count=56817) then 
       count <= "0000000000000000"; 
      else 
       count <= count + 1; 
      end if; 
      end if; 
    end process; 
end Behavioral; 

我未完成的代碼是這樣的

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.NUMERIC_STD.ALL; 

library UNISIM; 
use UNISIM.VComponents.all; 

entity Basic is 

    Port( clk : in STD_LOGIC; 
      note : out STD_LOGIC; 
      address: in integer range 0 to 31 
     ); 
end Basic; 

architecture Behavioral of Basic is 

    signal count : unsigned (15 downto 0) := (others => '0'); 
    signal reg_address : integer range 0 to 31 ; 
    type rom_array is array (0 to 31) of integer (4 downto 0); 
    constant rom: rom_array := ( "11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011", "11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011","11011", "11011", 
        "11011", "11011"); 
begin 

    note <= std_logic(count(15)); 
    process (clk) 
    begin 
      if rising_edge(clk) then 
       reg_address <= address; 
       if (reg_address < 32) then 
        if (count = rom(reg_address)) then 
         count <= "0000000000000000"; 
        else 
         count <= count + 1; 
        end if; 
       else 
        reg_address <= "00000"; 
       end if; 
      end if; 
      reg_address <= reg_address + 1; 
    end process; 
end Behavioral; 

的ROM值要改變。 我試圖通過分時鐘來產生聲音。就像25mhz/56818 = 440一樣。要想播放一首歌曲,我想創建一個充滿數字的ROM來劃分時鐘,然後做一個for循環播放歌曲。但我不能因爲循環不類似於java/C所以我想我需要繞過它。

我的錯誤是:

ERROR:HDLParsers:526 - "C:/Users/user/DigitalProje/Basic.vhd" Line 18. Non array type integer can not have a index constraint.

ERROR:HDLParsers:3312 - "C:/Users/user/DigitalProje/Basic.vhd" Line 19. Undefined symbol 'rom_array'.

ERROR:HDLParsers:1209 - "C:/Users/user/DigitalProje/Basic.vhd" Line 19. rom_array: Undefined symbol (last report in this block)

ERROR:HDLParsers:3285 - "C:/Users/user/DigitalProje/Basic.vhd" Line 19. No array or record type can be found that has elements of types matching the aggregate.

ERROR:HDLParsers:532 - "C:/Users/user/DigitalProje/Basic.vhd" Line 19. Deferred constant are allowed only in packages.

ERROR:HDLParsers:808 - "C:/Users/user/DigitalProje/Basic.vhd" Line 35. = can not have such operands in this context.

ERROR:HDLParsers:800 - "C:/Users/user/DigitalProje/Basic.vhd" Line 41. Type of reg_address is incompatible with type of 00000.

+0

熊,如果你迭代儘管每個一旦前一個完成,你只會在每個頻率上產生一個單獨的轉換。爲了按順序播放「音符」,您需要基於(慢得多)穩定的時鐘遍歷音符列表,以便能夠聽到每個不同的音調。您也無法使用此方法覆蓋色調。這就是爲什麼音樂音頻文件(未壓縮時)每秒存儲24,000次以上的幅度測量結果以複製可能由許多單獨音調組成的實際波形。 – QuantumRipple

+0

對不起,打擾你進一步,但我是一個初學者,我不知道如何使用嵌入式以外的時鐘。你能詳細說明嗎? – Strider

+0

有幾種方法可以從現有時鐘生成較慢的時鐘。大多數FPGA都有專用的時鐘操作模塊,可以通過各種方式對時鐘進行倍增或分頻,但您也可以像使用音頻發生器一樣使用計數器生成分頻時鐘。當計數器翻轉而不是實際的單獨時鐘時,我可能會在25MHz(主時鐘)域上進行處理,以增加筆記ROM的地址。這使用時鐘啓用來獲得所需的減速而不必處理多個時鐘域。 – QuantumRipple

回答

0

VHDL是強類型語言,所以你必須嚴格要求的類型。

兩個問題,rom_arrayinteger型的元件,但它看起來像的意圖可能已經使用基於恆定分配到rom無符號(或另一種載體類型);所以也許這樣做:

type rom_array is array (0 to 31) of unsigned (4 downto 0); 

reg_address是整數,因此不能用繩子像reg_address <= "00000";分配,所以認爲這更改爲:記

reg_address <= 0; 
+0

但是當我這樣做時,我不能添加數字像56000 65000到數組 – Strider

+0

其實你可以,你只需要將它們轉換爲無符號('to_unsigned(整數,寬度)'),並使用足夠寬的無符號來處理您想要使用的最大值。 – QuantumRipple