
程序给你做出来了,完全符合你的要求。仿真的话时间用的太长,就仿了一个set1set2=00的50M的2500分频20k的,图也给你贴出来,不过频率太高,已经看不出clk的波形了。
程序:
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_arithall;
use ieeestd_logic_unsignedall;
entity fen is
port(
clk,set1,set2:in std_logic;
out1:out std_logic);
end ;
architecture arch of fen is
signal a:std_logic;
begin
process(clk)
variable data:integer range 0 to 50000;
begin
if clk'event and clk='1' then
if set1='0' and set2='0' then
if data=2500 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
elsif set1='0' and set2='1' then
if data=10000 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
elsif set1='0' and set2='1' then
if data=50000 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
end if;
end if;
end process;
end arch;
VHDL不允许在一个进程中检测多个信号的边沿,只能检测某一个信号的边沿。if clk'event and clk='1'then if PUSH_IN'EVENT AND PUSH_IN='0' THEN 这种描述方式VHDL不认可。
--一顿早饭的时间写的,综合仿真均已通过,放分吧~
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
use ieeestd_logic_arithall;
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;
就是用内部时钟对外部时钟进行计数,假如你的内部时钟3m,首先定义一个计数器,如果检测到管脚的上升沿就加1,如果检测到下降沿就去判断这个计数值是多少,如果在3k的范围内,变可以确定是3k了。
注意不要以为3m采样3k方波的高电平一定是512个计数值,信号不可能很稳定,只能取一个范围。
这个很简单,假定我们需要的方波占空比为50%,要产生方波输出,肯定是需要一个时钟信号。
产生思路:对时钟进行周期计数,计数器的最大值由时钟频率和输出方波频率决定。
不妨设计数器的最大值为6,则根据计数器的值就可以产生出三相差120度的方波
第一路输出信号在计数器值为0时变为高电平,在计数器值为3时变为低电平
第二路输出信号在计数器值为2时变为高电平,在计数器值为5时变为低电平
第三路输出信号在计数器值为1时变为低电平,在计数器值为4时变为高电平
如此就可以实现,具体参数可以根据实际情况来确定,建议使用VHDL/Verilog编写程序。
以上就是关于【菜鸟求教:请用vhdl语言设计一个分频器。100分拜谢!!!】全部的内容,包括:【菜鸟求教:请用vhdl语言设计一个分频器。100分拜谢!!!】、VHDL 脉冲检测程序设计、求帮写VHDL,将50mhz分频6个频率,驱动蜂鸣器,产生6种不同声音等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)