2017-04-21 55 views
0

我只想在下面的源文章中發表評論,但我沒有這個特權,所以我想我可能會問一個問題,以便我可以得到一些澄清。這個VHDL代碼是如何工作的?

how to delay a signal for several cycles in vhdl

基本上我需要執行2個時鐘週期的延遲這一進程位於我的VHDL項目的行爲(代碼如下所示爲其中):

process(font_address(0), font_address(1), font_address(2), font_address(3),font_address(4), font_address(5), font_address(6), font_address(7),vga_hcount(0), vga_hcount(1),vga_hcount(2),CLK) 

begin 




--if (CLK'event and CLK = '1') then 
    -- a_store <= a_store(1 downto 0) & a; 
    -- a_out <= a_store(1 downto 0); 
--end if; 

if (CLK'event and CLK = '1') then 
case vga_hcount(2 downto 0) is 
when "000" => font_bit <= font_data(7); 
when "001" => font_bit <= font_data(6); 
when "010" => font_bit <= font_data(5); 
when "011" => font_bit <= font_data(4); 
when "100" => font_bit <= font_data(3); 
when "101" => font_bit <= font_data(2); 
when "110" => font_bit <= font_data(1); 
when "111" => font_bit <= font_data(0); 
when others => font_bit <= font_data(0); 
end case; 
end if; 



end process; 

正如你所看到的我已經做了這樣的事情,在進程中的信號分配需要一個時鐘週期延遲之前,由if語句在信號分配周圍提供,但我似乎無法創建可合成的2個時鐘脈衝延遲,儘管讀取回答了上面鏈接的問題

當我評論的if語句周圍的情況下包裹並取消下面的代碼塊

if (CLK'event and CLK = '1') then 
a_store <= a_store(1 downto 0) & a; 
a_out <= a_store(1 downto 0); 
end if; 

這是一個從這個問題,我得到以下錯誤的開頭給出的鏈接採取:

[Synth 8-690]賦值中的寬度不匹配;目標有2位,源有3位[「U:/計算機組織實驗室/ vga/vga_prac.vhd」:304]

此錯誤消息中引用的目標是a_store向量,源是級聯a_store和a。

這是我將邏輯1分配給a並創建a_store和a_out作爲std_logic_vectors與2個元素(因爲我想延遲兩個時鐘週期)。我認爲我得到這個錯誤的原因是因爲即使在閱讀了這個問題幾個小時之後,我仍然無法理解它實際上應該如何產生2個時鐘週期的延遲。

我認爲最初可能是1位通過a_store向量迭代,直到MSB爲1,然後將此向量應用於a_out,但查看它在所有if語句中的事實,我不能看看這兩行代碼甚至可以執行多次。如果這是真的,我將不得不做一些測試,以確保a_out在其MSB中有1。

通常我會繼續前進,但經過廣泛的搜索後,我找不到比這更簡單的解決方案,儘管事實上我並不完全瞭解它應該如何工作。

如果有人可以澄清這一點或建議對我的程序進行修改,這將會產生所需的延遲,這將是非常好的。

在此先感謝,

Simon。

+1

有在這個過程中靈敏度列表許多不必要的名稱。只有'CLK'是必需的。 – JHBonarius

+1

您聲稱從另一個問題複製/粘貼的代碼實際上是不同的。 –

+1

Martin對你的鏈接問題的回答顯示'a_store <= a_store(store'high-1 downto 0)& a;'這給出了正確的答案。在下降範圍(downto)'high給出左邊界的指數值。對於具有兩個元素1 downto 0的數組子類型,這將是a_store(0 downto 0)包含一個元素的數組值。你的問題是你沒有忠實地執行馬丁的回答。您還可以提供[MCVe](https://stackoverflow.com/help/mcve),以便可以看到聲明。另外'font_bit <= font_data(to_integer(unsigned(not vga_hcount(2 downto 0))));'一個8輸入多路複用器。 – user1155120

回答

2

首先,第一代碼是不是有效的,並且可以減少到

use ieee.numeric_std.all; 
[...] 

process(CLK) 
begin 
    if rising_edge(CLK) then 
     font_bit <= font_data(7 - to_integer(unsigned(vga_hcount(2 downto 0)))); 
    end if; 
end process; 

對於第二部分,誤差說的一切。你說a_store有2位(或者稱之爲「元素」),那麼你可以想象a_store(1 downto 0) & aa_store的兩位+ a = 1位的3位。您不能將3位分配給2位。那會合適嗎?分配a_out的同樣問題:2位如何適合1位?

因此:

if (CLK'event and CLK = '1') then 
    a_store <= a_store(0) & a; 
    a_out <= a_store(1); 
end if; 
+0

感謝您的反饋,當我回到實驗室時,我會進行此更改並查看它是否正常工作。 – burton01

+0

這個工作只有我不得不將a_store(1 downto 0)分配給a_out,而不是你在這裏完成的。不過謝謝。 – burton01

+0

@ burton01由於您沒有提供完整的代碼,這可能是真的。我只是建議正常的兩個時鐘延遲的代碼。 – JHBonarius