2016-11-06 42 views
3

我有這個簡單的VHDL代碼aufg4.vhdVHDL重新分配整數信號不按`report`聲明不行

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity aufg4 is 
    Port ( 
     clock : in std_logic 
      ); 
end aufg4; 

architecture Behavioral of aufg4 is 

    signal tut_counter : integer range 0 to 90 := 0; -- counts tutorial time 

begin 

    do_process :process(clock) 
     begin 
      if(rising_edge(clock)) then 
       report "tut_counter " & integer'image(tut_counter); 
       if(tut_counter >= 90) then 
        tut_counter <= 0; 
        report "tut_counter reset"; 
       end if; 
       tut_counter <= tut_counter + 1; 
      end if; 
     end process; 

end Behavioral; 

而且測試平臺aufg4_tb.vhd

LIBRARY ieee; 
USE ieee.std_logic_1164.ALL; 

ENTITY aufg4_tb IS 
END aufg4_tb; 

ARCHITECTURE behavior OF aufg4_tb IS 

    COMPONENT aufg4 
    PORT(
     clock : IN std_logic 
     ); 
    END COMPONENT; 

    --Inputs 
    signal clock : std_logic := '0'; 

    -- Clock period definitions 
    constant clock_period : time := 10 ns; 

BEGIN 

    -- Instantiate the Unit Under Test (UUT) 
    uut: aufg4 PORT MAP (
    clock => clock 
     ); 

    -- Clock process definitions 
    clock_process :process 
    begin 
     clock <= '0'; 
     wait for clock_period/2; 
     clock <= '1'; 
     wait for clock_period/2; 
    end process; 

END; 

當我模擬行爲模型report輸出:

... 
at 885 ns(1): Note: tut_counter 88 (/aufg4_tb/uut/). 
at 895 ns(1): Note: tut_counter 89 (/aufg4_tb/uut/). 
at 905 ns(1): Note: tut_counter 90 (/aufg4_tb/uut/). 
at 905 ns(1): Note: tut_counter reset (/aufg4_tb/uut/). 
at 915 ns(1): Note: tut_counter 91 (/aufg4_tb/uut/). 
at 915 ns(1): Note: tut_counter reset (/aufg4_tb/uut/). 
at 925 ns(1): Note: tut_counter 92 (/aufg4_tb/uut/). 
at 925 ns(1): Note: tut_counter reset (/aufg4_tb/uut/). 
at 935 ns(1): Note: tut_counter 93 (/aufg4_tb/uut/). 
... 

所以if -statement正常工作,但信號tut_counter的重新分配不起作用。

那麼爲什麼呢?

爲什麼模擬不會通過一個錯誤,因爲tut_counter只有一個範圍從0 to 90

+1

http://stackoverflow.com/questions/13954193/is-process-in-vhdl-reentrant/13956532#13956532 –

+2

+1了良好問順便問一下。至於爲什麼它沒有報告錯誤 - 無可否認,您正在使用Xilinx ISIM。這是默認情況下打破,並且多年來一直這樣,但有一個「屬性」選項(我認爲在「高級」選項卡下)來打開範圍檢查並修復它。 –

+0

@BrianDrummond我怎樣才能得到這種重新分配'事件'正常工作? – goulashsoup

回答

-1

使用else可以很好地解決問題!

do_process :process(clock) 
    begin 
     if(rising_edge(clock)) then 
      report "tut_counter " & integer'image(tut_counter); 
      if(tut_counter >= 90) then 
       tut_counter := 0; 
       report "tut_counter reset"; 
      else 
       tut_counter := tut_counter + 1; 
      end if; 
     end if; 
    end process; 

否則,你可以使用一個變量:variable tut_counter : integer range 0 to 90 := 0; -- counts tutorial time

+0

Sorta。這會將計數器重置爲1,而不是0。將得到0,1,2,...,90,1,2,3 ...... 90,1,2 ......注意Brian關於'else'語句的觀點 – PlayDough

+0

除了位如果這實際上並沒有解決問題,那麼使用信號完全正常工作的變量是產生低效合成硬件和難以識別錯誤的好方法。如果你剛纔移動了「'tut_counter <= tut_counter + 1;'」如果(tut_counter> = 90)然後是''它會工作得很好(避免覆蓋一個任務)'else'子句中的''如果(tut_counter> = 90)。 – QuantumRipple

+0

是的,我知道...... @QuantumRipple爲什麼VHDL確實有變量不允許使用它們? – goulashsoup