
这个很简单,假定我们需要的方波占空比为50%,要产生方波输出,肯定是需要一个时钟信号。
产生思路:对时钟进行周期计数,计数器的最大值由时钟频率和输出方波频率决定。
不妨设计数器的最大值为6,则根据计数器的值就可以产生出三相差120度的方波
第一路输出信号在计数器值为0时变为高电平,在计数器值为3时变为低电平
第二路输出信号在计数器值为2时变为高电平,在计数器值为5时变为低电平
第三路输出信号在计数器值为1时变为低电平,在计数器值为4时变为高电平
如此就可以实现,具体参数可以根据实际情况来确定,建议使用VHDL/Verilog编写程序。
--一顿早饭的时间写的,综合仿真均已通过,放分吧~
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;
设计个计数器,以T=n为周期,到n后重新从0开始计数,同时产生脉冲,使输出PWM的管脚电平取反。在0-n之间再取个数,当计数值N=d时也产生一个脉冲使得PWM管脚取反。d/n就是占空比,n固定,改变d就可以改变占空比,分辨率为1/n。
给个参考思路吧。。。很久没用VHDL了,不能编出现成的了。
以上就是关于用FPGA产生三相差为120的方波的程序及原理图全部的内容,包括:用FPGA产生三相差为120的方波的程序及原理图、求帮写VHDL,将50mhz分频6个频率,驱动蜂鸣器,产生6种不同声音、怎样用VHDL语言实现PWM波的占空比可调等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)