老曦子博客

记录我学习生活的小博客(FPGA/SOPC)

« [学习记录]三速以太网(Triple Speed Ethernet)VHDL并转串其实很容易 »

VHDL生成PWM是很简单的

多位的数据赋值给单位数据的方法很好的解决PWM的问题。

代码如下:

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity pwm_test is
  port (
   clk : in std_logic;
   PWM_in : in std_logic_vector (7 downto 0) := "00000000";
   PWM_out : out std_logic
  );
end pwm_test;

architecture PWM_arch of pwm_test is
  signal  PWM_Accumulator : std_logic_vector(8 downto 0);
begin
  process(clk, PWM_in)
  begin
    if rising_edge(clk) then     
      PWM_Accumulator  <=  ("0" & PWM_Accumulator(7 downto 0)) + ("0" & PWM_in);
    end if;
  end process;

  PWM_out <= PWM_Accumulator(8);
end PWM_arch;

热文排行

随机文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80722

Laoxizi's Blog FPGA/SOPC 文章转载请联系作者