cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
961 Views
Registered: ‎11-07-2017

Write output stream from tb to a file

Hello everyone, I am trying to write the output of a state register to a file, 8 bits at a time. My testbench should take the output (z_out) and continually add the values onto separate lines on a text file, until a reset condition is met.

 

If anyone can point me in the in the correct direction or assist me in any way, it would be greatly appreciated.

 

 

--
---
---
---
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_SIGNED.all;
USE IEEE.STD_LOGIC_TEXTIO.ALL;
USE STD.TEXTIO.ALL;


entity _rtl_tb is

end rtl_tb;

architecture Behavioral of rtl_tb is

	component rtl port(
		clk	: in std_logic;
		clk_en :in std_logic;
		rst :  in std_logic;
		load: in std_logic;
		z_valid : out std_logic;
		z_out	: out std_logic_vector(7 downto 0)
							);
	end component;
	
	--Signal Inputs
	signal clk : std_logic := '0';
	signal clk_en :	std_logic := '0';
	signal rst : std_logic :=  '0';
	signal load : std_logic := '0';


	--Signal Outputs

	signal z_valid : std_logic := '0';
	signal z_out : std_logic_vector(7 downto 0);
	signal z_buffer : std_logic_vector(7 downto 0);

	
	--Intermediate Signals
	signal count_tb	: integer range 0 to 2047;
	
	--Clock period definitions
	constant clk_period : time := 8 ns; -- Set	for 125Mhz reference clock

	signal write_flag : std_logic := '0'; -- Flag to set for end of output file
    
    signal count : STD_LOGIC_vector(3 downto 0) := "0000";

-- Functions

	begin
	-- port map
		
		uut : rtl port map(
			clk => clk,
			clk_en =>clk_en,
			rst => rst,
			z_valid => z_valid,
			z_out => z_out);
			
	-- Simulate Cik from cikperiod Currently set to 125MHz
		clk_process : process
			begin
				clk <= '0';
				wait for clk_period/2;
				clk <= '1';
				wait for clk_period/2;
				clk <= '0';
			end process;
			
		-- clock_counter : process
			-- begin
				-- loop
				-- clk_ticks <= clk_ticks + 1;
				-- wait for clk_period;
				-- end loop;
			-- end process;
			
		 
		instructions : process
			begin
			     wait for 100 ns;
				 rst <= '1';-- Start with a wee reset
				 wait for 100 ns;
				 rst <= '0';	-- release reset
				wait for 100 ns;

				clk_en <= '1';	-- Set elk en to high
				load <= '1';
				wait for 8 ns;
				load <= '0';
				
				wait for 500 ns;
				rst <='1';
				wait for 10 ns;
				rst <= '0';
				wait;
				
			end process;
			
            
            writing_stage : process is
                    
					file myfile : TEXT open write_mode is "z_out.txt";
                    variable L1: LINE;        
                    Variable temp : std_logic_vector (7 downto 0);

                    Begin
						wait for 10 ns;

						if (clk_en='1') then
							temp :=z_out;
						write(l1,temp);
						writeline(myfile,l1);
						end if;
                    wait;
                    end process;		
	
end Behavioral;
0 Kudos
3 Replies
Highlighted
902 Views
Registered: ‎03-27-2014

Re: Write output stream from tb to a file

@lucozade_energy,

 

writing_stage : process(clock)
file myfile: text is out "test.txt";
variable myline: line;

begin
if rising_edge(clock) then
   if (tvalid = '1') then
      write(myline, now); -- known keyword
      write(myline, string(" hello ")); -- requires library std.textio
      write(myline, tdata); -- requires ieee.std_logic_textio
      write(myline, tvalid); -- requires ieee.std_logic_textio
      write(myline, tdata_real); -- requires std.textio
      writeline(myfile, myline); -- append
   end if;
end if;



 

G.W.,
NIST - Time Frequency metrology
0 Kudos
869 Views
Registered: ‎11-07-2017

Re: Write output stream from tb to a file

It creates a file that is blank. Since the tb is based on a process and I am just monitoring the Z_out in the main file, do I need to save a copy to a buffer?

0 Kudos
Highlighted
867 Views
Registered: ‎11-07-2017

Re: Write output stream from tb to a file

Ok , I have fixed the issue, it was to do with my clk_enable. Now i have to format it so it shows the following:

 

<Number> <Time> <Hex Value>

e.g:

1  500ns  1D

2 750ns   2F 

....................

0 Kudos