脉冲宽度调制 ( 脉宽调制 )是一种非常流行的调制技术,主要用于控制传递到电气设备(例如电动机)的功率。
这个 VHDL项目 提出了一个简单的可变占空比。在Xilinx ISIM上进行了仿真和验证。

具有可变占空比:
-- fpga4student.com: FPGA Projects, Verilog projects, VHDL项目 -- 脉宽调制 发生器的VHDL代码 -- Two de-bounced push-buttons -- One: increase duty cycle by 10% -- Another: Decrease duty cycle by 10% library IEEE; use IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; entity 脉宽调制 _Generator is port ( clk: in std_logic; -- 100MHz clock input DUTY_INCREASE: in std_logic; -- button to increase duty cycle by 10% DUTY_DECREASE: in std_logic; -- button to decrease duty cycle by 10% 脉宽调制 _OUT: out std_logic -- 脉宽调制 signal out with frequency of 10MHz ); end 脉宽调制 _Generator; architecture Behavioral of 脉宽调制 _Generator is -- D-Flip-Flop for debouncing module component DFF_Debounce Port ( CLK : in std_logic;
en : in std_logic; D : in std_logic; Q : out std_logic ); end component; signal slow_clk_en: std_logic:='0'; -- slow clock enable for debouncing signal counter_slow: std_logic_vector(27 downto 0):=(others => '0');-- counter for creating slow clock signal tmp1,tmp2,duty_inc: std_logic;-- temporary signals for deboucing signal tmp3,tmp4,duty_dec: std_logic;-- temporary signals for deboucing signal counter_PWM: std_logic_vector(3 downto 0):=(others => '0');-- counter for 脉宽调制 signal signal DUTY_CYCLE: std_logic_vector(3 downto 0):=x"5"; begin -- Debouncing process -- First generate slow clock enable for deboucing (4Hz) process(clk) begin if(rising_edge(clk)) then counter_slow <= counter_slow + x"0000001"; --if(counter_slow>=x"17D7840") then -- for running on FPGA -- comment when running simulation if(counter_slow>=x"0000001") then -- for running simulation -- comment when running on FPGA counter_slow <= x"0000000"; end if; end if; end process; --slow_clk_en <= '1' when counter_slow = x"17D7840" else '0';-- for running on FPGA -- comment when running simulation
slow_clk_en <= '1' when counter_slow = x"000001" else '0';-- for running simulation -- comment when running on FPGA -- debounce part for duty increasing button stage0: DFF_Debounce port map(clk,slow_clk_en , DUTY_INCREASE, tmp1); stage1: DFF_Debounce port map(clk,slow_clk_en , tmp1, tmp2); duty_inc <= tmp1 and (not tmp2) and slow_clk_en;
-- debounce part for duty decreasing button stage2: DFF_Debounce port map(clk,slow_clk_en , DUTY_DECREASE, tmp3); stage3: DFF_Debounce port map(clk,slow_clk_en , tmp3, tmp4); duty_dec <= tmp3 and (not tmp4) and slow_clk_en;
-- for controlling duty cycle by these buttons process(clk) begin if(rising_edge(clk)) then if(duty_inc='1' and DUTY_CYCLE <= x"9") then DUTY_CYCLE <= DUTY_CYCLE + x"1";--increase duty cycle by 10% elsif(duty_dec='1' and DUTY_CYCLE>=x"1") then DUTY_CYCLE <= DUTY_CYCLE - x"1";--decrease duty cycle by 10% end if; end if; end process; -- Create 10MHz 脉宽调制 signal process(clk) begin if(rising_edge(clk)) then counter_PWM <= counter_PWM + x"1"; if(counter_PWM>=x"9") then counter_PWM <= x"0"; end if; end if; end process; 脉宽调制 _OUT <= '1' when counter_PWM < DUTY_CYCLE else '0'; end Behavioral; library IEEE; use IEEE.STD_LOGIC_1164.ALL; -- fpga4student.com: FPGA项目 , Verilog projects, VHDL项目 -- D触发器的VHDL代码 -- D-Flip-Flop for debouncing module entity DFF_Debounce is Port ( CLK : in std_logic;
en: in std_logic; D : in std_logic; Q : out std_logic ); end DFF_Debounce; architecture Behavioral of DFF_Debounce is begin process(CLK) begin if (rising_edge(CLK)) then
if (en='1') then Q <= D; end if;
end if; end process; end Behavioral;
具有可变占空比的PWM发生器的VHDL测试平台代码:
-- fpga4student.com: FPGA项目 , Verilog projects, VHDL项目 -- VHDL testbench code for 脉宽调制 Generator LIBRARY ieee; USE ieee.std_logic_1164.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --USE ieee.numeric_std.ALL; ENTITY tb_PWM_Genenrator IS END tb_PWM_Genenrator; ARCHITECTURE behavior OF tb_PWM_Genenrator IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT 脉宽调制 _Generator PORT( clk : IN std_logic; DUTY_INCREASE : IN std_logic; DUTY_DECREASE : IN std_logic; 脉宽调制 _OUT : OUT std_logic ); END COMPONENT; --Inputs signal clk : std_logic := '0'; signal DUTY_INCREASE : std_logic := '0'; signal DUTY_DECREASE : std_logic := '0'; --Outputs signal 脉宽调制 _OUT : std_logic; -- Clock period definitions constant clk_period : time := 10 ns; BEGIN -- Instantiate the Unit Under Test (UUT) uut: 脉宽调制 _Generator PORT MAP ( clk => clk, DUTY_INCREASE => DUTY_INCREASE, DUTY_DECREASE => DUTY_DECREASE, 脉宽调制 _OUT => 脉宽调制 _OUT ); -- Clock process definitions clk_process :process begin clk <= '0'; wait for clk_period/2; clk <= '1'; wait for clk_period/2; end process; -- Stimulus process stim_proc: process begin DUTY_INCREASE <= '0'; DUTY_DECREASE <= '0'; wait for clk_period*10; DUTY_INCREASE <= '1'; wait for clk_period*10; DUTY_INCREASE <= '0'; wait for clk_period*10; DUTY_INCREASE <= '1'; wait for clk_period*10; DUTY_INCREASE <= '0'; wait for clk_period*10; DUTY_INCREASE <= '1'; wait for clk_period*10; DUTY_INCREASE <= '0'; wait for clk_period*10; DUTY_DECREASE <= '1'; wait for clk_period*10; DUTY_DECREASE <= '0'; wait for clk_period*10; DUTY_DECREASE <= '1'; wait for clk_period*10; DUTY_DECREASE <= '0'; wait for clk_period*10; DUTY_DECREASE <= '1'; wait for clk_period*10; DUTY_DECREASE <= '0'; wait for clk_period*10; -- insert stimulus here wait; end process; END;
VHDL中PWM发生器的仿真结果:

推荐的 VHDL项目 :
1. 什么是FPGA? VHDL如何在FPGA上工作
2. FIFO存储器的VHDL代码
3. FIR滤波器的VHDL代码
4. 8位微控制器的VHDL代码
5. 矩阵乘法的VHDL代码
6. 开关尾环计数器的VHDL代码
7. FPGA上数字闹钟的VHDL代码
8. 8位比较器的VHDL代码
9. 如何使用VHDL将文本文件加载到FPGA中
10。 D触发器的VHDL代码
11。 完整加法器的VHDL代码
12 具有可变占空比的VHDL中的PWM发生器
13 ALU的VHDL代码
14。 带测试平台的计数器的VHDL代码
15 16位ALU的VHDL代码
16。 VHDL中的移位器设计
17。 VHDL中的非线性查找表实现
18岁 VHDL中的密码协处理器设计
19 Verilog和VHDL :通过示例解释
20 FPGA上时钟分频器的VHDL代码
21 如何生成时钟使能信号而不是创建另一个时钟域
22 VHDL代码,用于反跳FPGA上的按钮
23。 交通信号灯控制器的VHDL代码
24 用于简单2位比较器的VHDL代码
25岁 单端口RAM的VHDL代码
22 VHDL代码,用于反跳FPGA上的按钮
23。 交通信号灯控制器的VHDL代码
24 用于简单2位比较器的VHDL代码
25岁 单端口RAM的VHDL代码
26 使用FSM的停车场系统的VHDL代码
27。 VHDL编码与软件编程
1. 什么是FPGA? VHDL如何在FPGA上工作
2. FIFO存储器的VHDL代码
3. FIR滤波器的VHDL代码
4. 8位微控制器的VHDL代码
5. 矩阵乘法的VHDL代码
6. 开关尾环计数器的VHDL代码
7. FPGA上数字闹钟的VHDL代码
8. 8位比较器的VHDL代码
9. 如何使用VHDL将文本文件加载到FPGA中
10。 D触发器的VHDL代码
11。 完整加法器的VHDL代码
12 具有可变占空比的VHDL中的PWM发生器
13 ALU的VHDL代码
14。 带测试平台的计数器的VHDL代码
15 16位ALU的VHDL代码
16。 VHDL中的移位器设计
17。 VHDL中的非线性查找表实现
18岁 VHDL中的密码协处理器设计
19 Verilog和VHDL :通过示例解释
20 FPGA上时钟分频器的VHDL代码
21 如何生成时钟使能信号而不是创建另一个时钟域
22 VHDL代码,用于反跳FPGA上的按钮
23。 交通信号灯控制器的VHDL代码
24 用于简单2位比较器的VHDL代码
25岁 单端口RAM的VHDL代码
22 VHDL代码,用于反跳FPGA上的按钮
23。 交通信号灯控制器的VHDL代码
24 用于简单2位比较器的VHDL代码
25岁 单端口RAM的VHDL代码
26 使用FSM的停车场系统的VHDL代码
27。 VHDL编码与软件编程
能否请您提供三相pwm vhdl代码。
回复 删除提供三相pwm脉冲代码
回复 删除您正在使用哪个板?时钟频率是多少?辛苦了
回复 删除