我正在做一個音樂盒與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.
熊,如果你迭代儘管每個一旦前一個完成,你只會在每個頻率上產生一個單獨的轉換。爲了按順序播放「音符」,您需要基於(慢得多)穩定的時鐘遍歷音符列表,以便能夠聽到每個不同的音調。您也無法使用此方法覆蓋色調。這就是爲什麼音樂音頻文件(未壓縮時)每秒存儲24,000次以上的幅度測量結果以複製可能由許多單獨音調組成的實際波形。 – QuantumRipple
對不起,打擾你進一步,但我是一個初學者,我不知道如何使用嵌入式以外的時鐘。你能詳細說明嗎? – Strider
有幾種方法可以從現有時鐘生成較慢的時鐘。大多數FPGA都有專用的時鐘操作模塊,可以通過各種方式對時鐘進行倍增或分頻,但您也可以像使用音頻發生器一樣使用計數器生成分頻時鐘。當計數器翻轉而不是實際的單獨時鐘時,我可能會在25MHz(主時鐘)域上進行處理,以增加筆記ROM的地址。這使用時鐘啓用來獲得所需的減速而不必處理多個時鐘域。 – QuantumRipple