?? ringcall_1.vhd
字號:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY ringcall_1 IS
PORT
(
clk : IN STD_LOGIC;--時鐘輸入,產生鈴聲;
choose : IN STD_LOGIC_vector(1 downto 0); --鈴聲選擇
ena : IN STD_LOGIC;--鈴聲使能
r : OUT STD_LOGIC--鈴聲輸出
);
END ringcall_1;
ARCHITECTURE a OF ringcall_1 IS
SIGNAL overspks: std_logic;--tone為音調控制,overspks計數溢出,count2初始輸出
--考慮到演示時指示燈的頻率區別程度,取total_dig_count=1000,則輸出T依次為1000(800,500,100)/f(clk)(s),
--建議f(clk)取為1kHZ,則T對應為1(0.8,0.5,0.1)(s)
--若要得到相應的樂曲音調則應先確定外部時鐘,然后確定total_dig_count,再根據公式計算出相應的tone
BEGIN
--數字分頻器
process(clk,overspks)
variable tone,dig_count:integer range 0 to 20000; --total_dig_count=1000,取整便于計算
--但一般來說total_dig_count取2^n可以使數字分頻器得到足夠多的分頻
variable count2:std_logic;
begin
case choose is
--f(輸出)=f(clk)/(2*(total_dig_count-tone))
when "00" => tone:=5000;
--組成樂曲
--variable temp: integer 0 to time; --time節拍數由使能信號ena的持續時間與輸出信號的周期決定,盡量取大使鈴聲響足時間
--while (temp<time or ena='0') loop
-- temp:=temp + 1;
-- case temp is
-- when 1 =>tone<=a;
-- when 2 => tone<=b;
-- .
-- .
-- .
-- when time => tone<=c;
-- when others => tone<=d;
-- end case;
-- end loop;
--或者可以在之前接一個ROM存儲好鈴聲音樂,用使能信號激勵,在時鐘節拍下串行輸出,還可以進行鈴聲編輯
--中音7,987.76hz,tone=494
when "01" => tone:=6000;
--高音1,1046.50hz,tone=522
when "10" => tone:=7500;
--高音2,1174.66hz,tone=575
when others => tone:=9500;
--高音3,1318.51hz,tone=621
end case;
if ( clk'event and clk='1') then
if ena='1' then
if dig_count=10000 then
dig_count:=tone; --若記滿,將預置數重新置入
overspks<='1'; --產生overspks溢出信號
else dig_count:=dig_count+1; --否則繼續加計數
overspks<='0';
end if ;
end if;
end if;
--將輸出再進行二分頻,展寬脈沖使揚聲器有足夠的功率發音
if (overspks'event and overspks='1') then
count2:=not count2;
end if;
r<=count2 and ena ;
end process;
end a;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -