2014-10-08 76 views
1

我有兩個新手問題。我正嘗試將數組中的數據輸出到vhdl上的文本文件中。儘管引用了許多在線指南來做到這一點,但我總是想出一個「不存在的文件」。有什麼問題的任何建議?未實例化文本輸出文件

其次,當我嘗試使用下面的數組信號作爲寫入函數的參數時,它會給出錯誤。我還可以如何使用非常量數據作爲操作數?

entity Top_Module is 
Port (clk : in STD_LOGIC); 
end Top_Module; 

architecture Behavioral of Top_Module is 

type array_1 is array (0 to 127) of integer range -128 to 127; 
signal sample_1: array_1 := (104,40,-40,-104,-128,-104,-40,40,104,127,104,40,40,-4); 
constant a :std_logic_vector(3 downto 0):= "0111"; 
begin 


process(clk) -- process for writing the outputs to the "*.txt" file 
file result_file: text is out "fft_output.txt"; 
variable outline:line; 
constant tmp_fft:integer:=0; 
begin 
    if(clk'event and clk='1') then 
       --tmp_fft :=to_integer(signed(sample_1)); 
       write(outline,a); 
       writeline(result_file,outline); 
    end if; 
end process; 

回答

1

文件聲明VHDL 1987語法,所以用這個代替嘗試:

file result_file : text open write_mode is "fft_output.txt"; 

您的代碼不會表現出來,但我相信你包括std.textio包 像:

library std; 
use std.textio.all; 

在VHDL 2002中,這個軟件包不知道如何製作(寫入)linestd_logic_vectorwrite(outline, a)中嘗試。因此,如果您使用的是VHDL 2002,則可能是因爲在write過程中支持std_logic_vector 參數。

非標準Synopsys軟件包std_logic_textio在大多數 工具中都可用,並且包含用於std_logic_vector的寫入功能。該軟件包可以 與使用:

library ieee; 
use ieee.std_logic_textio.all; 

VHDL 2008標準增加了在 std_logic_1164std_logic_vector寫支持,所以你可能要檢查模擬器你使用具有對VHDL這個功能的支持是 請注意,bwritehwrite也支持二進制和十六進制 輸出。

注意合成使用write和一般textio是不可能的,因爲這些都是基於line類型,而這又是一個access型,類似於在其他語言中的指針類型,而這不能被合成。對於綜合來說,使用David Koontz的答案中的slv_image函數。

+0

感謝您的及時答覆。我做了你所建議的調整,但是當寫入過程接受向量時,只有當它們不變時纔會這樣做。使用信號不可能達到這個目的嗎?我將要輸入數據。 當綜合出現以下錯誤: 錯誤:地圖:116 - 設計是空的。不會進行處理。 錯誤:映射:52 - 遇到處理RPM時遇到問題。 任何想法? – BayK 2014-10-09 21:08:42

1

除了Morten的回答,您也沒有在合計默認值中代表sample_1的每個元素,可以通過在右括號之前附加, others => 0來解決。

因爲您的VHDL設計規範是符合IEEE Std 1076-1987標準的,所以使用ghdl的--std = 87標誌使用我坐下來的字符串轉換例程創建了一點點。 (而缺乏「-1987中值不屑):

library ieee; 
use ieee.std_logic_1164.all; 
use std.textio.all; 

entity Top_Module is 
Port (clk : in std_logic); 
end Top_Module; 

architecture Behavioral of Top_Module is 
    function slv_image(constant inp: std_logic_vector) return string is 
     variable image_str: string (1 to inp'length); 
     alias input_str: std_logic_vector (1 to inp'length) is inp; 
    begin 
     for i in input_str'range loop 
      case input_str(i) is 
       when 'U' => image_str(i) := 'U'; 
       when 'X' => image_str(i) := 'X'; 
       when '0' => image_str(i) := '0'; 
       when '1' => image_str(i) := '1'; 
       when 'Z' => image_str(i) := 'Z'; 
       when 'H' => image_str(i) := 'H'; 
       when 'L' => image_str(i) := 'L'; 
       when 'W' => image_str(i) := 'W'; 
       when '-' => image_str(i) := '-'; 
      -- image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i))); 
      end case; 
     end loop; 
     return image_str; 
    end; 
    type array_1 is array (0 to 127) of integer range -128 to 127; 
    signal sample_1: array_1 := (104,40,-40,-104,-128,-104,-40,40,104,127,104,40,40,-4, others => 0); 
    constant a : std_logic_vector(3 downto 0):= "0111"; 
begin 

Unlabelled: 
    process(clk) -- process for writing the outputs to the "*.txt" file 
     file result_file: text is out "fft_output.txt"; 
     -- file result_file : text open write_mode is "fft_output.txt"; 
     variable outline: line; 
     constant tmp_fft:integer := 0; 
    begin 
     if(clk'event and clk='1') then 
        --tmp_fft :=to_integer(signed(sample_1)); 
        write(outline,slv_image(a)); 
        writeline(result_file,outline); 
     end if; 
    end process; 
end Behavioral; -- architecture; 

隨着測試平臺:

library ieee; 
use ieee.std_logic_1164.all; 

entity tb_topmod is 
end tb_topmod; 

architecture foo of tb_topmod is 
    signal clk: std_logic := '0'; 
    component Top_Module -- no is 
     Port (clk : in std_logic); 
    end component; 
    for DUT: Top_Module use entity work.Top_Module(Behavioral); 
begin 
DUT: 
    Top_Module -- entity work.Top_Module 
     port map (clk => clk); 
CLOCK: 
    process 
    begin 
     wait for 20 ns; 
     clk <= not clk; 
     if Now > 100 ns then 
      wait; 
     end if; 
    end process; 
end foo; 

ghdl -a --std=87 topmod.vhdl
ghdl -e --std=87 tb_topmod foo
ghdl -r tb_topmod foo

(其中分析,闡述和運行(模擬)的設計。 )

文件fft_output。TXT文件包含:

more fft*
0111
0111
0111

這與試驗檯的CLOCK過程中Now測試的預期輸出。您的設計規範僅爲a提供默認值。

現在你真的在使用VHDL -1987工具嗎?

+0

感謝您的詳細回覆。不,我實際上使用的是VHDL 2008。我失去了足夠的方向,我用我能找到的任何東西來編寫我所做的代碼。 – BayK 2014-10-09 21:06:01