2013-04-29 100 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;