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

📄 div_freq.vhd

📁 多功能电子琴 可以实现人性化界面 同时可以根据按键选择播放模式
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity div_freq is
	port(
		tune:in integer;	--range 0 to 21;
		clk:in std_logic;	--20MHz
		output:out std_logic
		);
end div_freq;

architecture code of div_freq is	
signal tmp_clk,tmp_out:std_logic;
signal count1,count2,count3,count4,count5,count6,count7,
		count8,count9,count10,count11,count12,count13,count14,
		count15,count16,count17,count18,count19,count20,count21:std_logic_vector(16 downto 0);
signal high_1,high_2,high_3,high_4,high_5,high_6,high_7:std_logic;
signal mid_1,mid_2,mid_3,mid_4,mid_5,mid_6,mid_7:std_logic;
signal low_1,low_2,low_3,low_4,low_5,low_6,low_7:std_logic;
begin
	high_do :				--divide 38218
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count1 = "00100101010100101")then		--38218/2
				count1 <= (others => '0');
				high_1 <= not high_1;
			else
				count1 <= count1 + 1;
			end if;
		end if;
	end process;

	mid_do : 				--divide 38218
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count8 = "01001010101001010")then		--38218/2
				count8 <= (others => '0');
				mid_1 <= not mid_1;
			else
				count8 <= count8 + 1;
			end if;
		end if;
	end process;
	
	low_do : 				--divide 38218
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count15 = "10010101010010100")then		--38218/2
				count15 <= (others => '0');
				low_1 <= not low_1;
			else
				count15 <= count15 + 1;
			end if;
		end if;
	end process;

	high_re : 				--divide 34054
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count2 = "00100001010000011")then		--34054/2
				count2 <= (others => '0');
				high_2 <= not high_2;
			else
				count2 <= count2 + 1;
			end if;
		end if;
	end process;

	mid_re : 				--divide 34054
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count9 = "01000010100000110")then		--34054/2
				count9 <= (others => '0');
				mid_2 <= not mid_2;
			else
				count9 <= count9 + 1;
			end if;
		end if;
	end process;

	low_re : 				--divide 34054
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count16 = "10000101000001100")then		--34054/2
				count16 <= (others => '0');
				low_2 <= not low_2;
			else
				count16 <= count16 + 1;
			end if;
		end if;
	end process;

	high_mi : 				--divide 30335
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count3 = "00011101100111111")then		--30335/2
				count3 <= (others => '0');
				high_3 <= not high_3;
			else
				count3 <= count3 + 1;
			end if;
		end if;
	end process;

	mid_mi : 				--divide 30335
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count10 = "00111011001111110")then		--30335/2
				count10 <= (others => '0');
				mid_3 <= not mid_3;
			else
				count10 <= count10 + 1;
			end if;
		end if;
	end process;

	low_mi : 				--divide 30335
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count17 = "01110110011111100")then		--30335/2
				count17 <= (others => '0');
				low_3 <= not low_3;
			else
				count17 <= count17 + 1;
			end if;
		end if;
	end process;

	high_fa : 				--divide 28632
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count4 = "00011011111101100")then		--28632/2
				count4 <= (others => '0');
				high_4 <= not high_4;
			else
				count4 <= count4 + 1;
			end if;
		end if;
	end process;

	mid_fa : 				--divide 28632
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count11 = "00110111111011000")then		--28632/2
				count11 <= (others => '0');
				mid_4 <= not mid_4;
			else
				count11 <= count11 + 1;
			end if;
		end if;
	end process;

	low_fa : 				--divide 28632
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count18 = "01101111110110000")then		--28632/2
				count18 <= (others => '0');
				low_4 <= not low_4;
			else
				count18 <= count18 + 1;
			end if;
		end if;
	end process;

	high_so : 				--divide 25510
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count5 = "00011000111010011")then		--25510/2
				count5 <= (others => '0');
				high_5 <= not high_5;
			else
				count5 <= count5 + 1;
			end if;
		end if;
	end process;

	mid_so : 				--divide 25510
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count12 = "00110001110100110")then		--25510/2
				count12 <= (others => '0');
				mid_5 <= not mid_5;
			else
				count12 <= count12 + 1;
			end if;
		end if;
	end process;

	low_so : 				--divide 25510
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count19 = "01100011101001100")then		--25510/2
				count19 <= (others => '0');
				low_5 <= not low_5;
			else
				count19 <= count19 + 1;
			end if;
		end if;
	end process;

	high_la : 				--divide 22727
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count6 = "00010110001100011")then		--22727/2
				count6 <= (others => '0');
				high_6 <= not high_6;
			else
				count6 <= count6 + 1;
			end if;
		end if;
	end process;

	mid_la : 				--divide 22727
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count13 = "00101100011000110")then		--22727/2
				count13 <= (others => '0');
				mid_6 <= not mid_6;
			else
				count13 <= count13 + 1;
			end if;
		end if;
	end process;

	low_la : 				--divide 22727
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count20 = "01011000110001100")then		--22727/2
				count20 <= (others => '0');
				low_6 <= not low_6;
			else
				count20 <= count20 + 1;
			end if;
		end if;
	end process;

	high_xi : 				--divide 20247
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count7 = "00010011110001011")then		--20247/2
				count7 <= (others => '0');
				high_7 <= not high_7;
			else
				count7 <= count7 + 1;
			end if;
		end if;
	end process;

	mid_xi : 				--divide 20247
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count14 = "00100111100010110")then		--20247/2
				count14 <= (others => '0');
				mid_7 <= not mid_7;
			else
				count14 <= count14 + 1;
			end if;
		end if;
	end process;

	low_xi : 				--divide 20247
	process(clk)
	begin
		if(clk'event and clk = '1')then
			if(count21 = "01001111000101100")then		--20247/2
				count21 <= (others => '0');
				low_7 <= not low_7;
			else
				count21 <= count21 + 1;
			end if;
		end if;
	end process;

	play:
	process(tune,low_1,low_2,low_3,low_4,low_5,low_6,low_7,
			mid_1,mid_2,mid_3,mid_4,mid_5,mid_6,mid_7,
			high_1,high_2,high_3,high_4,high_5,high_6,high_7)
	begin
		case tune is
			when 0 => tmp_out <= '0';
			when 1 => tmp_out <= low_1;
			when 2 => tmp_out <= low_2;
			when 3 => tmp_out <= low_3;
			when 4 => tmp_out <= low_4;
			when 5 => tmp_out <= low_5;
			when 6 => tmp_out <= low_6;
			when 7 => tmp_out <= low_7;
			when 8 => tmp_out <= mid_1;
			when 9 => tmp_out <= mid_2;
			when 10 => tmp_out <= mid_3;
			when 11 => tmp_out <= mid_4;
			when 12 => tmp_out <= mid_5;
			when 13 => tmp_out <= mid_6;
			when 14 => tmp_out <= mid_7;
			when 15 => tmp_out <= high_1;
			when 16 => tmp_out <= high_2;
			when 17 => tmp_out <= high_3;
			when 18 => tmp_out <= high_4;
			when 19 => tmp_out <= high_5;
			when 20 => tmp_out <= high_6;
			when 21 => tmp_out <= high_7;
			when others => tmp_out <= '0';
		end case;
	end process;

	output <= tmp_out;
end code;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -