2013-04-29 101 views
0

我正在使用VHDL进行离散余弦变换。我试图将VHDL代码从整数转换为标准逻辑向量。我申请了一些我在网上阅读和从教科书上阅读的技巧,但它没有奏效。以下是我尝试转换的代码。我希望输入长度为8位,输出长度为12位。谢谢。离散余弦变换使用VHDL

entity dct is 
    port (
      Clk :   in BIT; 
      Start :   in BIT; 
      Din :   in INTEGER; 
      Done :   out BIT; 
      Dout :   out INTEGER 
      ); 
end dct;  

architecture behavioral of dct is 
begin 
    process 
      type RF is array (0 to 7, 0 to 7) of INTEGER; 

      variable i, j, k  : INTEGER; 
      variable InBlock  : RF; 
      variable COSBlock  : RF; 
      variable TempBlock  : RF; 
      variable OutBlock  : RF; 
      variable A, B, P, Sum : INTEGER; 

    begin 

这是我在阅读一些书后试过的一本书,我不断收到错误。

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


entity dct is 
    port (
      Clk :   in std_logic; 
      Start :   in std_logic; 
      Din_temp:  in INTEGER; 
      temp := conv_std_logic_vector(Din_temp, 8); 
      Done :   out std_logic; 
      Dout_temp:  out INTEGER; 
      temp := conv_std_logic_vector(Dout_temp, 9)); 

end dct; 

architecture behavioral of dct is 
begin 
    process 
      type RF is matrix(0 to 7, 0 to 7) of ; 

      variable i, j, k  : std_logic_vector(7 downto 0); 
      variable InBlock  : RF; 
      variable COSBlock  : RF; 
      variable TempBlock  : RF; 
      variable OutBlock  : RF; 
      variable A, B, P, Sum : std_logic_vector(7 downto 0); 

    begin 

回答

0

似乎你将实体声明和信号分配结合起来;这不是这样工作的!保持实体原样并在架构内使用类型转换函数。下面的例子显示了这种用于DIN和DOUT:

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

entity dct is 
port (
     Clk :   in BIT; 
     Start :   in BIT; 
     Din :   in INTEGER; 
     Done :   out BIT; 
     Dout :   out INTEGER 
     ); 
end dct;  

architecture behavioral of dct is 
    signal temp_din: std_logic_vector(7 downto 0); 
    signal temp_dout: std_logic_vector(11 downto 0); 

begin 

    temp_din<=std_logic_Vector(to_unsigned(Din,8)); 
    Dout<=to_integer(unsigned(temp_dout)); 
    ... 
当然

,你也可以直接在你的实体使用std_logic_vector:

entity dct is 
port (
     Clk :   in BIT; 
     Start :   in BIT; 
     Din :   in std_logic_Vector(7 downto 0); 
     Done :   out BIT; 
     Dout :   out std_logic_vector(11 downto 0) 
     ); 
end dct;  
0

整数是完全可合成的工作就好了港口,因此,如果您拥有的模块工作令人满意,并且正确合成,保持良好状态。

它是使用范围的整数好的做法:例如,如果DIN,Dout的表示在0至255范围内的值,创建或者一个新的整数类型或它们的子类型:

type Int_8 is new Integer range 0 to 255; -- or 
subtype Int_8 is Integer range 0 to 255; 

(该区别在于子类型可以与其他整数自由混合,但意外地将新类型与整数混合将被编译器标记为错误)。

这样做的好处是,综合不会尝试创建只需要8位(或3或19位)的32位数学单位。通常情况下,然后修剪剩余位,所以它不会花费更多的门,它只是用“修剪冗余逻辑”消息填充报告文件...

但是我猜你遇到的问题是接口这个核心与设计的其他部分一起,以不太明智的方式实现,其中有std_logic_vector端口。

然后你可以实现一个包装器来使这个DCT核心适应std_logic_vector环境。 我对不同的端口信号使用了不同的技术:端口映射中的转换更加整洁,但是一些工具有处理它们的问题(错误)。所以我使用内部信号作为Start和Dout的适配器,以展示如何解决这些问题。 在现实中,选择一个或另一个!

library IEEE; 
    use IEEE.std_logic_1164.all; 
    use IEEE.numeric_std.all; 

    entity std_lv_dct is 
     port (
       Clk :   in std_logic; 
       Start :   in std_logic; 
       Din :   in std_logic_vector(7 downto 0); 
       Done :   out std_logic; 
       Dout :   out std_logic_vector(11 downto 0); 
       ); 
    end std_lv_dct;  

    architecture wrapper of std_lv_dct is 
     Dout_int : integer range 0 to 4095; 
     Start_int : bit; 
    begin 

    -- internal signals as type adapters 
    Dout  <= std_logic_vector(to_unsigned(Dout_int),11); 
    Start_int <= to_bit(Start); 

    -- direct entity instantiation for the real core 
    Transform : entity work.dct 
     port map(
       Clk => to_bit(Clk), 
       Start => Start_int, 
       Din => to_integer(unsigned(Din)), 
       std_logic(Done) => Done, 
       Dout => Dout_int 
       ); 

    end architecture wrapper;