3路SPWM波形正弦波脉宽调制VHDL代码仿真
名称:3路SPWM波形正弦波脉宽调制VHDL代码仿真(代码在文末下载)
软件:QuartusII
语言:VHDL
代码功能:
完成基于FPGA的SPWM发生器的设计,输出3路SPWM信号。
实现的方法:分别产生正弦波和三角波,将正弦波和三角波进行比较,三角波大于正弦波时输出1,否则输出0
FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com
演示视频:
设计文档:
1. 工程文件
2. 程序文件
3. 程序编译
4. RTL图
5. 仿真图
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; --三相spwm波 ENTITY Sweep_frequency IS PORT ( clk : IN STD_LOGIC;--时钟 PWM_wave1 : OUT STD_LOGIC;--输出PWM波形 PWM_wave2 : OUT STD_LOGIC;--输出PWM波形 PWM_wave3 : OUT STD_LOGIC--输出PWM波形 ); END Sweep_frequency; ARCHITECTURE behavioral OF Sweep_frequency IS --sin ROM表 COMPONENT sin_ROM IS PORT ( address: IN STD_LOGIC_VECTOR (9 DOWNTO 0); clock: IN STD_LOGIC := '1'; q: OUT STD_LOGIC_VECTOR (9 DOWNTO 0) ); END COMPONENT; --三角波 ROM表 COMPONENT triangle_ROM IS PORT ( address: IN STD_LOGIC_VECTOR (9 DOWNTO 0); clock: IN STD_LOGIC := '1'; q: OUT STD_LOGIC_VECTOR (9 DOWNTO 0) ); END COMPONENT; --相位累加器 COMPONENT Freq_sum IS PORT ( clk : IN STD_LOGIC; freq_data : IN STD_LOGIC_VECTOR(9 DOWNTO 0); freq_out : OUT STD_LOGIC_VECTOR(9 DOWNTO 0) ); END COMPONENT; --初相位调整 COMPONENT phase_crtl IS PORT ( clk : IN STD_LOGIC; freq_out : IN STD_LOGIC_VECTOR(9 DOWNTO 0);--相位累加器输出 phase_data : IN STD_LOGIC_VECTOR(9 DOWNTO 0);--相位控制字10bit address : OUT STD_LOGIC_VECTOR(9 DOWNTO 0)--查找表地址 ); END COMPONENT; SIGNAL address_1 : STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL address_2 : STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL address_3 : STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL freq_out_sin : STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL q_sin1 : STD_LOGIC_VECTOR(9 DOWNTO 0);--ROM输出波形 SIGNAL q_sin2 : STD_LOGIC_VECTOR(9 DOWNTO 0);--ROM输出波形 SIGNAL q_sin3 : STD_LOGIC_VECTOR(9 DOWNTO 0);--ROM输出波形 SIGNAL freq_out_triangle : STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL q_triangle : STD_LOGIC_VECTOR(9 DOWNTO 0);--ROM输出波形 BEGIN --sin存储Rom表 i1_sin_ROM : sin_ROM PORT MAP ( address => address_1,--查找表地址 clock => clk,--时钟 q => q_sin1--输出波形 ); --sin存储Rom表 i2_sin_ROM : sin_ROM PORT MAP ( address => address_2,--查找表地址 clock => clk,--时钟 q => q_sin2--输出波形 ); --sin存储Rom表 i3_sin_ROM : sin_ROM PORT MAP ( address => address_3,--查找表地址 clock => clk,--时钟 q => q_sin3--输出波形 ); --triangle存储Rom表 i_triangle_ROM : triangle_ROM PORT MAP ( address => freq_out_triangle,--查找表地址 clock => clk,--时钟 q => q_triangle--输出波形 ); --正弦波相位累加器 i0_Freq_sum : Freq_sum PORT MAP ( clk => clk, freq_data => "0000000001",--频率控制字10bit---- freq_out => freq_out_sin--累加器输出 ); --初相位调整-0 i1_phase_crtl: phase_crtl PORT MAP( clk => clk, freq_out => freq_out_sin,--累加器输出 phase_data => "0000000000",--相位控制字10bit address => address_1--查找表地址 ); --初相位调整-120 i2_phase_crtl: phase_crtl PORT MAP( clk => clk, freq_out => freq_out_sin,--累加器输出 phase_data => "0101010101",--相位控制字10bit address => address_2--查找表地址 ); --初相位调整-240 i3_phase_crtl: phase_crtl PORT MAP( clk => clk, freq_out => freq_out_sin,--累加器输出 phase_data => "1010101010",--相位控制字10bit address => address_3--查找表地址 ); --三角波相位累加器 i1_Freq_sum : Freq_sum PORT MAP ( clk => clk, freq_data => "0000010000",--频率控制字10bit freq_out => freq_out_triangle--累加器输出 ); PWM_wave1<='1' when freq_out_triangle>q_sin1 else '0';--三角波大于正弦波时输出1,否则输出0 PWM_wave2<='1' when freq_out_triangle>q_sin2 else '0';--三角波大于正弦波时输出1,否则输出0 PWM_wave3<='1' when freq_out_triangle>q_sin3 else '0';--三角波大于正弦波时输出1,否则输出0 END behavioral;
代码文件(付费下载):
发表评论