Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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中数字std无符号到std逻辑向量的转换_Vhdl_Fpga_Xilinx_Hdl_Intel Fpga - Fatal编程技术网

vhdl中数字std无符号到std逻辑向量的转换

vhdl中数字std无符号到std逻辑向量的转换,vhdl,fpga,xilinx,hdl,intel-fpga,Vhdl,Fpga,Xilinx,Hdl,Intel Fpga,我有一个关于从数字标准到标准逻辑向量转换的问题。我正在使用我在网上看到的移动平均滤波器代码,过滤我的ADC值以稳定这些值 过滤器包代码为: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package filterpack is subtype number is unsigned(27 downto 0); type numbers is array(natural range <>

我有一个关于从数字标准到标准逻辑向量转换的问题。我正在使用我在网上看到的移动平均滤波器代码,过滤我的ADC值以稳定这些值

过滤器包代码为:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

package filterpack is
  subtype number is unsigned(27 downto 0);
  type numbers is array(natural range <>) of number;
  function slv_to_num(signal slv: in std_logic_vector) return number;
  procedure MAF_filter(
    signal x: in    number;
    signal h: inout numbers;
    signal y: out   number
  );
end filterpack;

package body filterpack is

function slv_to_num(signal slv: in std_logic_vector) return number is
  variable x: number := (others => '0');
begin
  for i in slv'range loop
    if slv(i) = '1' then
      x(i+4) := '1';
    end if;
  end loop;
  return x;
end function slv_to_num;

procedure MAF_filter(
    signal x: in    number;
    signal h: inout numbers;
    signal y: out   number
  ) is
begin
  h(0) <= x + h(1);       -- h[n] = x[n] + h[n-1]
  y <= h(0) - h(h'high);  -- y[n] = h[n] - h[n-M]
end MAF_filter;

end package body filterpack;
我想将MAF_滤波器的输出转换为std_逻辑_向量(23到0)。谁能告诉我如何将过滤器输出“y”转换为“std_逻辑_向量”


非常感谢

您想用这4个额外的位做什么?您的类型
number
有28位,但您的信号
adc\u-dat
只有24位

如果可以丢弃它们,您可以使用:

adc_dat <= std_logic_vector(y(adc_dat'range));

转换必须解决两个问题:您注意到的类型差异,以及两个单词大小不同的事实

类型差异很简单:
std\u logic\u vector(y)
将为您提供正确的类型。因为这两种类型是相关类型,所以这只是一个强制转换

大小的差异。。。只有你知道怎么做


adc\u dat我使用了已经为MAF编写的代码。由于函数slv_to_num的定义,我不得不使用4个额外的位。我编辑了答案,并为您的函数
slv_to_num
adc_dat : out std_logic_vector (23 downto 0);
adc_dat <= std_logic_vector(y(adc_dat'range));
function slv_to_num(signal slv: in std_logic_vector) return number is
begin
  return number(slv & "0000");
end function slv_to_num;