Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/testing/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vhdl 基于fpga的pwm产生_Vhdl_Fpga_Pwm - Fatal编程技术网

Vhdl 基于fpga的pwm产生

Vhdl 基于fpga的pwm产生,vhdl,fpga,pwm,Vhdl,Fpga,Pwm,如何使用FPGA生成PWM信号?哪种方法是生成可变占空比的最佳方法 我试图通过使用以下代码来解决这个问题,但出现了两三个错误 这是我的代码: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use ieee.numeric_std.all; --use ieee.float_pkg.all; ---- Uncomment the f

如何使用FPGA生成PWM信号?哪种方法是生成可变占空比的最佳方法

我试图通过使用以下代码来解决这个问题,但出现了两三个错误

这是我的代码:

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

use ieee.numeric_std.all;
--use ieee.float_pkg.all;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.

--library UNISIM;
--use UNISIM.VComponents.all;

entity pwm_sne is
  Generic(
    sys_clk         :integer :=50000000;
    pwm_freq        :integer :=100000;
    bits_resolution :integer :=8
  );
  Port (
    clk : in  STD_LOGIC;
    rst : in  STD_LOGIC;
    k   : in  STD_LOGIC_VECTOR (7 downto 0);
    y   : out STD_LOGIC
  );
end pwm_sne;

architecture Behavioral of pwm_sne is
  signal cnt      :std_logic_vector(7 downto 0);
  signal flag     :std_logic;
  signal reg      :std_logic_vector(7 downto 0);
  --variable duty   :std_logic:=0;
begin
  process(clk,rst)
  begin
    if rst='1' then
      cnt<="00000000";
    elsif(clk'event and clk='1')then
      cnt<=cnt+"00000001";
    elsif cnt="11111111" then
      flag<='0';
      cnt<="00000000";
    end if;
  end process;

  process(clk,flag)
  begin
    if(clk'event and clk='1') then
      reg<=k;
    end if;
  end process;

  process(cnt,reg)
  begin
    if(flag='0')then
    elsif cnt>reg then
      y<=(reg/256)*100;
      --y<=duty;
    elsif cnt=reg then
      y<=(reg/256)*100;
    elsif cnt<=reg then
      y<=period;
      --y<=duty;
    end if;
  end process;
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.STD_LOGIC_ARITH.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
使用ieee.numeric_std.all;
--使用ieee.float_pkg.all;
----如果正在实例化,请取消对以下库声明的注释
----此代码中的任何Xilinx原语。
--UNISIM图书馆;
--使用UNISIM.VComponents.all;
实体pwm_sne是
一般的(
系统时钟:整数:=50000000;
脉宽调制频率:整数:=100000;
位分辨率:整数:=8
);
港口(
clk:标准逻辑中;
rst:标准逻辑中;
k:标准逻辑向量(7到0);
y:输出标准逻辑
);
结束pwm_sne;
pwm_sne的结构是
信号cnt:std_逻辑_向量(7到0);
信号标志:标准逻辑;
信号寄存器:标准逻辑向量(7到0);
--可变占空比:标准逻辑:=0;
开始
过程(时钟、rst)
开始
如果rst='1',则

cnt解决方案:对数字进行数学运算,而不是对不类型的比特包进行数学运算

如果
cnt,reg,k
自然范围0到255
,并且您将
cnt
与0或255进行比较,并向其中添加1,则这将正常工作。如果
k
必须是std\u logic\u向量,则在它和
reg
之间使用一个类型转换函数


还建议:删除非标准的
std_logic_arith和
std_logic_unsigned
libs,改用
numeric_std`

欢迎来到堆栈溢出。您可以帮助那些试图回答您的问题的人:添加测试台代码怎么样?请看如何更具体地说明您有哪些错误。发生了什么事?你以为会发生什么?尽管如此,这看起来并不正确:
elsif cnt=“11111111”然后
。您确定如果cnt=“11111111”那么它不应该是
?(如果是这样,您将需要一个额外的
end If;
)。错误消息是什么?同时分配std_logic
y
乘法运算符的结果(例如
yWell“Period not declared”的可能原因非常明显。并且没有已知的乘法运算符返回单个位(std_logic)这也是显而易见的。不那么显而易见的是,你正试图用这行代码做什么:弄清楚这一点并实际实现它将很容易。但是一个普通的PWM控制器会在Y上输出“0”或“1”。