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

📄 speaker.vhd

📁 扳动定义为“开始”(即enable)的开关后
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity speaker is
    Port ( clk : in std_logic;
           tonein : in integer range 0 to 2047;
           spks : out std_logic);
end speaker;

architecture Behavioral of speaker is

signal divclk,fullspks : std_logic;

begin
  divideclk:  process(clk)
    variable count : integer range 0 to 49;
  begin
    divclk <= '0';
	 if count=49 then 
	   divclk <= '1' ;
		count := 0;
	 elsif clk'event and clk='1' then
	   count := count + 1;
	 end if;
  end process;

  genspks: process(divclk,tonein)
    variable cnt : integer range 0 to 2047;
  begin
    if divclk'event and divclk='1' then
	   if cnt=2047 then
		  cnt := tonein;
		  fullspks <= '1';
		else
		  cnt := cnt + 1;
		  fullspks <='0';
		end if;
	 end if;
  end process;

  delayspks: process(fullspks)
    variable count1 : std_logic;
  begin
    if fullspks'event and fullspks='1' then
	   count1 := not count1;
		if count1='1' then
		  spks <= '1';
		else
		  spks <= '0';
		end if;
    end if;
  end process;

end Behavioral;

⌨️ 快捷键说明

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