Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with Undefined output, return from function

Status
Not open for further replies.

ghostridergr

Member level 1
Joined
Nov 22, 2011
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,590
Well this is my code:
Code:
library IEEE;
use IEEE.std_logic_1164.all;
use STD.TEXTIO.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity tb_file_test is
  generic
		(
			N :integer := 8
		);
end tb_file_test;


architecture TB_ARCHITECTURE of tb_file_test is
file IN_1_VECTORS: TEXT open READ_MODE is "input_1.txt";
file IN_2_VECTORS: TEXT open READ_MODE is "input_2.txt";
file OUT_VECTORS: TEXT open WRITE_MODE is "output.txt";
--here
type matrix is array(natural range<>) of signed(N-1 downto 0);
signal inp1,inp2: matrix(0 to 124);
signal a,b: signed(N-1 downto 0):= (others=>'0');
signal test:std_logic_vector(3*N-1 downto 0);

function sum_of_square( a1,b1: in signed(N-1 downto 0); previous_sum:in std_logic_vector(3*N-1 downto 0))return std_logic_vector is     
     variable temp_sum:std_logic_vector(3*N-1 downto 0):=(others=>'0');
     variable diff: signed(N-1 downto 0):=(others=>'0');
     variable square_diff: std_logic_vector(2*N-1 downto 0):=(others=>'0');
begin
  temp_sum:=previous_sum;
  diff:=a1-b1;
	square_diff:=ext(diff*diff,2*N);
	temp_sum:=ext(temp_sum+square_diff,3*N);
  return temp_sum;
end sum_of_square;

begin
             
    process
        variable IN_BUF: LINE;
        variable OUT_BUF: LINE;
        variable a_var,b_var : bit_vector(N-1 downto 0):= (others=>'0');
        variable i,j: integer;
        	
    begin
        i:=0;
        j:=0;
        while not ENDFILE(IN_1_VECTORS) loop
            READLINE(IN_1_VECTORS,IN_BUF);
            READ(IN_BUF,a_var);
            a<=signed(to_stdlogicvector(a_var));
            wait for 10 ns;
            inp1(i)<=a;
            i:=i+1;
        end loop;
        while not ENDFILE(IN_2_VECTORS) loop
            READLINE(IN_2_VECTORS,IN_BUF);
            READ(IN_BUF,b_var);
            b<=signed(to_stdlogicvector(b_var));
            wait for 10 ns;
            inp2(j)<=b;
            j:=j+1;
        end loop;
        test<=ext(sum_of_square("00001000","00000001","000000000000000000000000"),3*N);
  
    end process;
    
end TB_ARCHITECTURE;

my problem is that test remains UUUUUUUUUUUUUUUUUUUUUUUUUU and more my last element from input2.txt isn't stored in inp2 array (but i can see its value on signal b). So given as an input 3 elements in both txt's my array's contain values in inp1(0),inp1(1),inp1(2), inp2(0),inp2(1) as it should be, but not in inp2(2).

Can anyone help?
 

are you running the simulation for long enough? Do the files contain exactly 125 words to go into the arrays? If its shorter you wont fill the arrays, if its longer you'll get an array out of bounds error.
You need to run it for at least 2500 ns to complete both loops.

Finally - delete std_logic_arith and use numeric_std.
 

Well whenever I stop it, it stops at about 100 ns. No my files contain less values, i thought thta this wouldn not be a problem and i was curious why the first array is dispalyed correctly and the second not, as it is the same code.

Edit: I changed the dimensions of my array and again the same. I have test UUUU and mast element of inp2 array undefined again. The weird thing is that signal b has the correct value-the last one but this just doesn't store in array. And as i told you whenever I stop it, it stops at 100ns.
 
Last edited:

can you provide the two input files?

---------- Post added at 11:44 ---------- Previous post was at 11:42 ----------

Actually, the problem is quite simple.

Add a wait to the end of the process. Whats happening is that once its completed the files, there are no more wait statements, so the process is going round in an infinite loop.
 

can you provide the two input files?
input1.txt
00000111
00000001
00000011
00000101

input2.txt
00000100
00000110
00000001
00010000

I do not know why it stops, always at 100 ns, no matter for how much time i run it.
 

Its getting stuck in an infinite loop at 100ns, because the files are Ended and there are no waits outside the while loops.
 

Thanks!! It worked! I have commented out wait and when deleting the comments, I have deleted it too...
 

Remember that processes without a sensitivity list are just infinite loops. They need a wait statement to halt them.
 

Next on this: If I add this code after the reading of my arrays:
Code:
storing: for k in 0 to 3 loop
          inside: for l in 0 to 3 loop
            sum_of_square_all(k,l)<=signed(ext(sum_of_square(inp1(k),inp2(l),"000000000000000000000000"),3*N));
        end loop inside;
      end loop storing;
the elements sum_of_square_all(0,3)/(1,3),(2,3),(3,3) remain XXXXXXX while my inp2 and inp1 array are filled correctly. Also my programme gets stuck at line:
end loop inside.
Any help?
 

If it's X, it means you've assigned sum_of_square_all somewhere else - probably another process or outside of the process. You can only drive a signal from a single process.

If its stuck - have you forgotten waits again.

PS. If this is testbench code (which it will be as you're reading text file), the for loops do not have to use constants.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top