⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ringcall_1.vhd

📁 电子打铃器 在max plus 2 下编译通过
💻 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 + -