2013-12-15 13 views
2

我想在VHDL中製作磚塊。 一切都很順利,但我有一個奇怪的問題。 在我看到的一段代碼中,當球到達磚的邊緣時,我在數組中的索引(y,x)處將值更改爲'0'。問題是我的數組中的所有值都變爲0,即使球沒有移動(程序啓動時球沒有移動)。所有的值在數組中改變使用vhdl

process(Ball_x1,Ball_x2,Ball_y1,Ball_y2) begin 
    x1 <= 280 + (x * 55); --edges of my brick 
    x2 <= 280 + ((x + 1) * 55); 
    y1 <= 108 + (y * 13); 
    y2 <= 108 + ((y + 1) * 13); 
    waardeArray := level1(y,x); 
    if (vcnt >= y1) and (vcnt <= y2) then 
     if (Ball_x1 >= x1) and (Ball_x1 <= x2) then -- edges of my ball 
      if waardeArray = '1' then 
       level1(y,x) := '0'; 
      end if; 
     end if; 
    end if; 
end process; 

我的陣列的聲明是

type levels is array (0 to 3, 0 to 5) of bit; 
shared variable level1 : levels := (
            ('1','0','0','0','0','1'), 
            ('0','1','0','0','1','0'), 
            ('0','0','1','1','0','0'), 
            ('0','0','1','1','0','0') 

            ); 

接着變量用於陣列的值存儲在位置(Y,X)

shared variable waardeArray: bit; 

這是使用意圖Ball_x2等,但我只是試着用我的球的一個邊緣來測試代碼。

更新

process(Ball_x1,Ball_x2,Ball_y1,Ball_y2) begin 
    x1 <= 280 + (x * 55); -- edges of my brick 
    x2 <= 280 + ((x + 1) * 55); 
    y1 <= 108 + (y * 13); 
    y2 <= 108 + ((y + 1) * 13); 
    if (vcnt >= y1) and (vcnt <= y2) then --vcnt is from another component where I send my data to my screen 
     if (Ball_x1 >= x1) and (Ball_x1 <= x2) then -- left edge of my ball 
      if level1(y)(x) = '1' then 
       level1(y)(x) <= '1'; --I do this to test if the elements with value 1 stay 1 and the 0 stay 0 ata initialization, but every element in my array change to 1. 
      else 
       level1(y)(x) <= level1(y)(x); 
      end if; 
     end if; 
    end if; 
end process; 

聲明

signal x: integer range 0 to 6 := 0; --Six is used for something else. 
signal y: integer range 0 to 3 := 0;  

signal x1: integer range 279 to 616; 
signal x2: integer range 279 to 616; 
signal y1: integer range 107 to 228; 
signal y2: integer range 107 to 228; 

signal color: std_logic_vector (7 downto 0) := "00000111"; 

type levels is array (0 to 3) of std_logic_vector (5 downto 0); 
signal level1 : levels := ("101101", 
            "010010", 
            "001100", 
            "001100"); 

這是我的本意

enter image description here

+0

什麼陣列正在改變;它是'waardeArray'還是'level1'?很難 挖掘更多這沒有至少聲明,所以你可能會考慮 發佈所有相關的代碼。此外,在該過程中僅使用靈敏度列表 中的第一個參數,因此最後三個以 'Ball_x2'開頭的參數可以被刪除。您可能會在回答中找到一些有用的信息 http://stackoverflow.com/a/20492018/2352082和 http://stackoverflow.com/a/20526229/2352082。 –

+0

有了一個共享變量,它可能會在另一個進程中更新,所以也許你必須在其他地方尋找更改的地方。 –

+0

在其他進程中,我只使用我的數組的值,我沒有改變任何東西。只有在這個過程中。 – GCallie

回答

0

不要使用共享變量。如果您需要在進程之間傳遞值,請使用信號。您無法確定與讀取操作相比,使用共享變量進行更新的順序。那麼,你可以,但你必須使用受保護的類型。

另外,在您的過程中,您正在查看x,yvcnt的值。但是這些信號(我希望它們不是共享變量的信號:)不在過程的敏感列表中,所以當它們發生變化時,過程不會被觸發。

+0

我將所有共享變量都改爲信號,但即使這樣我的數組中的所有元素都變爲1. 只能在球移動時啓動進程,而不是在更改數組索引時啓動。 我改變我的陣列也STD_LOGIC_VECTOR元素的一維數組,並更改STD_LOGIC_VECTOR的值,但即使如此,我也有同樣的問題。 – GCallie

+0

你可以編輯你的問題,包括現在的代碼。還有你的測試平臺,以及一些仿真波形,顯示當相對於其他感興趣的信號變化爲'1'時, –

+0

到目前爲止,我沒有製作任何測試臺。我用VHDL不太好,但是,我應該儘快做出來。 – GCallie