2015-12-23 43 views
1

我試圖使用變量作爲索引訪問std_logic_vector的一部分。使用變量作爲索引訪問std_logic_vector的一部分

以下過程會從一個功能shift_val結果,然後使用它來計算索引中提取我們需要在shift_data_in_s

6位數據我收到的最後一行的模擬誤差:6上LHS

shift_data_in_s <= data_in_e(to_integer(unsigned(msb_pos)) downto to_integer(unsigned(lsb_pos)))

說「數組大小不匹配的1上數組大小RHS」

我想初始化上lsb_posmsb_pos將解決這個問題,但它沒有...不知道它是如何得到了相同的價值這兩個變量,如果我明確地減去計算它們來自不同常量的相同值。

signal shift_val_s  : std_logic_vector(3 downto 0); 
signal shift_data_in_s : std_logic_vector(5 downto 0); 
shift_in_proc : process(data_in, num_zeros_s) 

variable data_in_e  : std_logic_vector(15 downto 0); 
variable msb_pos  : std_logic_vector(4 downto 0) := "01110"; 
variable lsb_pos  : std_logic_vector(4 downto 0) := "01001"; 
begin 
    data_in_e := data_in & zeros_f(16 - data_in'length); 
    shift_val_s <= some_function(data_in_e); 
    if (to_integer(unsigned(shift_val)) >= 12) then 
    -- all zeros 
    shift_data_in_s <= (others => '0'); 
    else 
    -- we need only 6 significant bits from the data, 
    -- msb_pos <= 15 - num_zeros -1; 
    msb_pos := std_logic_vector("01110" - unsigned(('0' & shift_val_s))); 
    -- lsb_pos <= 15 - num_zeros -6; 
    lsb_pos := std_logic_vector("01001" - unsigned(('0' & shift_val_s))); 
    if (lsb_pos(4) = '1') then -- if -ve 
    shift_data_in_s <= data_in_e(to_integer(unsigned(msb_pos)) downto 0) & zeros_f(to_integer(unsigned(neg_f(lsb_pos)))); 
    else 
    shift_data_in_s <= data_in_e(to_integer(unsigned(msb_pos)) downto to_integer(unsigned(lsb_pos))); 
    end if; 
end if ; end process shift_in_proc; 
+0

這不是[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。沒有這些,你會得到基於經驗的觀點而不是基於事實的答案 - 「最可能的解釋」,「這裏的任何人都不可能直接診斷」。您還可以在該過程中分配信號shift_val_s,稍後將其用於右手錶達式中,而不需要插入等待語句。看來你想在這裏有一個變量?或者常量,'data_in'length'來自聲明的索引範圍,擺脫'some_function'以及'data_in_e'亞穩態值問題。 – user1155120

回答

0

您的變量lsb_pos的值取決於shift_val_s,這本身就是依賴於some_function - 你沒有提供該代碼。所以任何人都不可能直接診斷問題。

順便說一下您的代碼會更容易,如果你使用integer變量,如閱讀:

variable msb_pos  : integer range 0 to 31 := 14; 
variable lsb_pos  : integer range 0 to 31 := 9; 

最後一行就變成了:

shift_data_in_s <= data_in_e(msb_pos downto lsb_pos); 

如果您some_function返回一個整數,你可以計算出你的msb_pos原樣:

msb_pos := 14 - shift_val_s; 
lsb_pos := 9 - shift_val_s; 
+0

謝謝...同意msb_pos和lsb_pos取決於shift_val_s ..但shift_val_s是一個4位向量..不管它的值是什麼,我不應該爲msb_pos和lsb_pos得到不同的值嗎? – rgt

1

最可能的解釋是msb_poslsb_pos包含一個元值(即。非01HL數據),大概是因爲data_in無效。然後to_integer調用將返回0,給你一個1,而不是6的範圍。在任何情況下,你可以使用你的模擬器快速找到。

編輯

速戰速決,按您的評論:確保some_function總是返回非metavalue 4位向量。有很多方法可以做到這一點,但你可以簡單地做:

fixed_answer <= to_01(metaval_answer); -- remove metavals 

有一個在numeric_std一個to_01,這需要一個unsigned並返回一個unsigned。默認情況下,元值被轉換爲零。你仍然會在簡單的模擬中得到錯誤的答案,但至少模擬會繼續下去。

+0

是的,你是正確的時間0,data_in無效..但我不知道如何解決這個問題 – rgt

+0

看到我上面的編輯。 – EML

+0

非常感謝!! ..幫助我解決了這個問題.. – rgt

相關問題