早教吧作业答案频道 -->其他-->
求帮写VHDL,将50mhz分频6个频率,驱动蜂鸣器,产生6种不同声音
题目详情
求帮写VHDL,将50mhz分频6个频率,驱动蜂鸣器,产生6种不同声音
▼优质解答
答案和解析
--一顿早饭的时间写的,综合仿真均已通过,放分吧~
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity MusicBox is port
(
clk:in std_logic;--主频 可设置成50M
rst:in std_logic;--复位信号 低有效
selectin:in std_logic_vector(5 downto 0);--频率选择输入,因为只有一个输出,所以必须得有选择
final:out std_logic--频率输出
);
end entity;
architecture behav of MusicBox is
signal freqout:std_logic;
signal freq:std_logic_vector(16 downto 0);
signal cnt:std_logic_vector(16 downto 0);
constant do:std_logic_vector(16 downto 0):="10111110101111000";--do的频率256Hz,50M/256Hz≈195312再除以2是方波翻转周期97656,二进制10111110101111000
constant re:std_logic_vector(16 downto 0):="10101001100010101";--re的频率288Hz,计算同上
constant mi:std_logic_vector(16 downto 0):="10011000100101101";--mi的频率320Hz,计算同上
constant fa:std_logic_vector(16 downto 0):="10001110110001011";--fa的频率342Hz,计算同上
constant so:std_logic_vector(16 downto 0):="01111111001010000";--so的频率384Hz,计算同上
constant la:std_logic_vector(16 downto 0):="01110010100111101";--la的频率426Hz,计算同上
begin
final <= freqout;
process(clk,rst)
begin
if rst = '1' then
if rising_edge(clk) then
case selectin is
when "000001" => freq <= do;
when "000010" => freq <= re;
when "000100" => freq <= mi;
when "001000" => freq <= fa;
when "010000" => freq <= so;
when "100000" => freq <= la;
when others => freq <= "00000000000000000";
end case;
if freq = "00000000000000000" then--没有输入则不响
freqout <= '0';--假设输出低则蜂鸣器不响
else
if cnt = freq then--计数器
cnt <= "00000000000000000";
freqout <= not freqout;--输出取反<=>输出方波
else
cnt <= cnt + 1;
end if;
end if;
end if;
else --复位信号有效时
freqout <= '0';
freq <= "00000000000000000";
cnt <= "00000000000000000";
end if;
end process;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity MusicBox is port
(
clk:in std_logic;--主频 可设置成50M
rst:in std_logic;--复位信号 低有效
selectin:in std_logic_vector(5 downto 0);--频率选择输入,因为只有一个输出,所以必须得有选择
final:out std_logic--频率输出
);
end entity;
architecture behav of MusicBox is
signal freqout:std_logic;
signal freq:std_logic_vector(16 downto 0);
signal cnt:std_logic_vector(16 downto 0);
constant do:std_logic_vector(16 downto 0):="10111110101111000";--do的频率256Hz,50M/256Hz≈195312再除以2是方波翻转周期97656,二进制10111110101111000
constant re:std_logic_vector(16 downto 0):="10101001100010101";--re的频率288Hz,计算同上
constant mi:std_logic_vector(16 downto 0):="10011000100101101";--mi的频率320Hz,计算同上
constant fa:std_logic_vector(16 downto 0):="10001110110001011";--fa的频率342Hz,计算同上
constant so:std_logic_vector(16 downto 0):="01111111001010000";--so的频率384Hz,计算同上
constant la:std_logic_vector(16 downto 0):="01110010100111101";--la的频率426Hz,计算同上
begin
final <= freqout;
process(clk,rst)
begin
if rst = '1' then
if rising_edge(clk) then
case selectin is
when "000001" => freq <= do;
when "000010" => freq <= re;
when "000100" => freq <= mi;
when "001000" => freq <= fa;
when "010000" => freq <= so;
when "100000" => freq <= la;
when others => freq <= "00000000000000000";
end case;
if freq = "00000000000000000" then--没有输入则不响
freqout <= '0';--假设输出低则蜂鸣器不响
else
if cnt = freq then--计数器
cnt <= "00000000000000000";
freqout <= not freqout;--输出取反<=>输出方波
else
cnt <= cnt + 1;
end if;
end if;
end if;
else --复位信号有效时
freqout <= '0';
freq <= "00000000000000000";
cnt <= "00000000000000000";
end if;
end process;
end architecture;
看了 求帮写VHDL,将50mhz...的网友还看了以下:
按要求写出相应的字母的大小写1.元音字母:2.含有/ei/音3.含有/i:/音4.含有/ai/音5 2020-05-14 …
汉语拼音大写字母按顺序的读音及写法要手写体哦,有一个大写的拼音,挨着一个小写的拼音,读法用汉字描述 2020-05-16 …
3同2的条件,写了A0=OE,还要写即d等于r再写所以是相切吗?4同2的条件,已经知道半径,求距离 2020-05-17 …
求这几个英文拼写的发音phu-kirtruing-ta-cha-non全拼是这样PhukirtRu 2020-05-17 …
问一下《基本乐理教程》练习七第四题和第九题的答案写出下列调式的调号并写上宫音与主音:F商G羽A角D 2020-06-11 …
什么情况下英语中d发dʒ的音?在哪些单词中d发dʒ的音(三个以上)求神级正解 2020-06-14 …
在学校图书馆的走廊里写着“慢步轻声”,其中“轻声”是指人说话声音的()A.音调B.响度C.音色D. 2020-06-20 …
常用音乐记号的记法、声乐演唱形式.[名称][记法]声乐演唱形式顿音不写重音不写上波音不写下波音不写 2020-06-26 …
1、看拼音,写词语,并将所写汉字按音序重排dígàixùnyìguī荡()灌()()色洋()玫() 2020-07-03 …
would有没简写,或者同音的?would这个单词有没有简写吖?或者同音的英文?懂英文的帮我简写一 2020-07-24 …