EmbDev.net

Forum: FPGA, VHDL & Verilog synthesizable 2-dimentional array with generic variables


von Meli (Guest)


Attached files:

Rate this post
useful
not useful
Hello,
Not so long from last appearance!
I've got a problem, Lothar, synthesizing the generic mux code with 
Design Compiler. As I know, it is not possible to synthesize a 
2-dimentinal array with generic parameters in DC. So, I thought of 
defining a new type like "wire" which is an array of std_logic_vector. 
Some colleagues told me this type might be synthesizable. But I have 
problem defining the new type with constant variables.
I attach the *.VHD file. Is it not really possible to define an aray 
type with variable?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Meli wrote:
> Is it not really possible to define an aray type with variable?
What has to be "variable"?

In general in VHDL you have 2 ways to define an array. Have a look at 
this:
http://www.lothar-miller.de/s9y/archives/39-Mehrdimensionale-Arrays.html
(maybe Google translateor can help...  ;-)
The major difference is in the acces to array elements:
1
  output0 <= FeldA(cnthi)(cntlo);
2
  output1 <= FeldB(cnthi, cntlo);
And of course you can use generics or constants to define the size of an 
array.

von Meli (Guest)


Rate this post
useful
not useful
Thanks Lothar. I know about the arrays and the way I can use the 
generics to describe the size of the arrays, but the point is that,to 
the best of my knowledge, this type of array declaration is not 
synthesizable by Design Compiler, using a generic for denoting the size.
As I posted before, someone told me that one solution for this problem 
is to define a type of a 2D array in a package, and I did so. But to 
define such an array I still need the generics, hence, I used constants 
to describe the size of the array. But it seems like those constants are 
not recognized in the package, and the error says "The identifier % is 
not defined".
Would u please take a look at the code and guide me through this 
problem?
Thanks in advance

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
Meli wrote:
> this type of array declaration is not synthesizable by Design Compiler,
> using a generic for denoting the size.
May be it wasn't in the last millennium, but now of course it is...

> But it seems like those constants are not recognized in the package
>  constant s is integer range 1 to 5 := 1;
A constant is defined in a different way (and also it has no range, 
because it is constant)...

> "The identifier % is not defined".
Have a look how a package is defined. And you will see that a package 
starts with the keyword library, and you will also see, thet each 
entity starts with the keyword library. And you will also see, that 
your VHDL code doesn't...

von Meli (Guest)


Rate this post
useful
not useful
Thanks Lothar. I will apply the changes and will report the result.
U r a real help, thank u for your time and comments. ;-)

von Meli (Guest)


Rate this post
useful
not useful
Deat Lothar,
As you mentioned, the line for using the work library was missing.
Also, there were some synthax errors like defining the constant is done 
with ":" not "is".
So, with applied changes the code worked.
Thanks again
:-)

von Meli (Guest)


Attached files:

Rate this post
useful
not useful
Lothar Miller wrote:
> Meli wrote:
>> this type of array declaration is not synthesizable by Design Compiler,
>> using a generic for denoting the size.
> May be it wasn't in the last millennium, but now of course it is...
>
>> But it seems like those constants are not recognized in the package
>>  constant s is integer range 1 to 5 := 1;
> A constant is defined in a different way (and also it has no range,
> because it is constant)...
>
>> "The identifier % is not defined".
> Have a look how a package is defined. And you will see that a package
> starts with the keyword library, and you will also see, thet each
> entity starts with the keyword library. And you will also see, that
> your VHDL code doesn't...

Dear Lothar,
Regarding your last helpful comments, I finally got to design the 
generic mux and it was synthesized successfully in DC. Now I'm gonna 
test it with a testbench. I wrote the testbench and it has no errors and 
is simulated, but the waveforms show "U" for input and output ports. Can 
you please help me solve the problem?

I attach the *.vhd code of my testbench, which also contains the mux 
block.

Best Regards and thank you in advance

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Meli wrote:
> but the waveforms show "U" for input and output ports.
Are you simulating the wrong module?


BTW:
1
  TDinput(2**s -1 downto 0)(line_width-1 downto 0) <= temp2(2**s -1 downto 0)(line_width-1 downto 0);
TDinput is the same type and size like tem2. Therefore you can write it 
shorter:
1
  TDinput <= temp2;

BTW2:
Instead of writing a bunch of vectors like this:
1
    Tsel <= "00000"; wait for 10 ns;    
2
    Tsel <= "00001"; wait for 10 ns;        
3
    Tsel <= "00010"; wait for 10 ns;    
4
    Tsel <= "00011"; wait for 10 ns;        
5
    :
6
    :
7
    Tsel <= "11101"; wait for 10 ns;    
8
    Tsel <= "11110"; wait for 10 ns;    
9
    Tsel <= "11111"; wait for 10 ns;
You could do it this way:
1
   for i in 0 to 2**s-1 loop
2
      Tsel <= std_logic_vector(to_unsigned(i,s));
3
      wait for 10 ns;    
4
   end loop;

And also this here:
1
  temp2(0)(line_width-1 downto 0) <= temp1(0);
2
  temp2(1)(line_width-1 downto 0) <= temp1(1);
3
  :
4
  :
5
  temp2(29)(line_width-1 downto 0) <= temp1(29);
6
  temp2(30)(line_width-1 downto 0) <= temp1(30);
7
  temp2(31)(line_width-1 downto 0) <= temp1(31);
Taken a similar loop it will look like:
1
   for i in 0 to 2**s-1 loop
2
     temp2(i)(line_width-1 downto 0) <= temp1(i);
3
   end loop;

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
Meli wrote:
> I wrote the testbench and it has no errors and is simulated, but the
> waveforms show "U" for input and output ports.
Yes, i also see them.

And now the question is: WHY?

And thats what a testbench is made for: to find design errors.

Now answer the question: why does the whole input look like rubbish?

And further on: why do the assignments to Tem2 and temp1 occur very 
delayed (320ns too late)?

Its because you wrote all of the assignments in ONE monster process. 
This process is stepped through and the values are saaigned to signals 
at the end of the process or at the very next wait statement. Just 
have a look in your VHDL book about the behaviour of signals inside a 
process. It is very essential to understand this behaviour!

Try the attached files and start thinking on your own. I urge you 
to...

von Meli (Guest)


Rate this post
useful
not useful
Thanks dear Lothar.
I know the better way of coding for the assignments, but since I'm 
frustrated with confiusing errors, I decide to code elementarily and 
then, after a successful compilation, I optimize my code.
OK, I'll look in my book again. You are right, the delayed signals are 
due to huge processes, but the "U" value for the ports doesn't seem to 
relate to the size of the process, does it?

von Meli (Guest)


Rate this post
useful
not useful
OMG!
It worked!
I took the assignment of TDinput out of the process and made the 
assignments as you mentioned, Lothar, and it worked!
1
begin
2
  UUT: Generic_Mux
3
  port map ( Dinput => TDinput, sel => Tsel, output => Toutput);
4
 
5
  temp1(0)<= std_logic_vector(to_signed (1,line_width));
6
  temp1(1)<= std_logic_vector(to_signed (0,line_width));
7
  temp1(2)<= std_logic_vector(to_signed (1,line_width));
8
  temp1(3)<= std_logic_vector(to_signed (1,line_width));
9
  temp1(4)<= std_logic_vector(to_signed (0,line_width));
10
  temp1(5)<= std_logic_vector(to_signed (0,line_width));
11
  temp1(6)<= std_logic_vector(to_signed (1,line_width));
12
  temp1(7)<= std_logic_vector(to_signed (0,line_width));
13
  
14
  temp1(8)<= std_logic_vector(to_signed (0,line_width));
15
  temp1(9)<= std_logic_vector(to_signed (0,line_width));
16
  temp1(10)<= std_logic_vector(to_signed (0,line_width));
17
  temp1(11)<= std_logic_vector(to_signed (0,line_width));
18
  temp1(12)<= std_logic_vector(to_signed (1,line_width));
19
  temp1(13)<= std_logic_vector(to_signed (1,line_width));
20
  temp1(14)<= std_logic_vector(to_signed (1,line_width));
21
  temp1(15)<= std_logic_vector(to_signed (0,line_width));
22
    
23
  temp1(16)<= std_logic_vector(to_signed (1,line_width));
24
  temp1(17)<= std_logic_vector(to_signed (1,line_width));
25
  temp1(18)<= std_logic_vector(to_signed (0,line_width));
26
  temp1(19)<= std_logic_vector(to_signed (0,line_width));
27
  temp1(20)<= std_logic_vector(to_signed (1,line_width));
28
  temp1(21)<= std_logic_vector(to_signed (0,line_width));
29
  temp1(22)<= std_logic_vector(to_signed (0,line_width));
30
  temp1(23)<= std_logic_vector(to_signed (1,line_width));
31
    
32
  temp1(24)<= std_logic_vector(to_signed (1,line_width));
33
  temp1(25)<= std_logic_vector(to_signed (1,line_width));
34
  temp1(26)<= std_logic_vector(to_signed (1,line_width));
35
  temp1(27)<= std_logic_vector(to_signed (0,line_width));
36
  temp1(28)<= std_logic_vector(to_signed (1,line_width));
37
  temp1(29)<= std_logic_vector(to_signed (1,line_width));
38
  temp1(30)<= std_logic_vector(to_signed (0,line_width));
39
  temp1(31)<= std_logic_vector(to_signed (1,line_width));
40
  
41
G:for i in 0 to 2**s-1 generate
42
     temp2(i)(line_width-1 downto 0) <= temp1(i);
43
  end generate;
44
45
    TDinput <= temp2;
46
    
47
P:process
48
 begin
49
   
50
 for i in 0 to 2**s-1 loop
51
      Tsel <= std_logic_vector(to_unsigned(i,s));
52
      wait for 10 ns;    
53
 end loop;
54
        
55
 end process;

So, it really matters that assignments are applied through a generate 
loop or one by one?! Why is that? It wasn't mentioned on the book!
Thanks again Lothar. You would be a great teacher (if you aren't one!).

kind regards

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
>So, it really matters that assignments are applied through a generate loop or one 
by one?!
No. The "loop vs. one by one" isn't the solution of this particular 
problem! But it's very different (!) whether you assign values to a 
signal in a process or as a concurrent description.

> Whyis that? Itwasn't mentioned on the book!
A book has one major flaw: everything has the same priority. You cannot 
use bold for the important things and more bold for the more important 
ones. So everything has same important...
But be sure: this behavior will be described in every VHDL book...

> Thanks again Lothar.
You're welcome.

> You would be a great teacher (if you aren't one!).
I'm not... ;-)

von Meli (Guest)


Rate this post
useful
not useful
Oh, yeah! The point is in the difference of concurrent assignment vs. 
one-by-one in a process. But I still can't get why it didn't work when I 
assigned the values to the TDinput in a process. It definitely delayed 
the values but why it showed "U" eternally?!
By the way, could you please take another look to the post of :

http://embdev.net/topic/303196#new

I wanna express my highly gratitude in advance for your helpful 
comments.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
Meli wrote:
> But I still can't get why it didn't work when I assigned the values to
> the TDinput in a process. It definitely delayed the values but why it
> showed "U" eternally?!
The assignment
1
    TDinput(2**s -1 downto 0)(line_width-1 downto 0) <= temp2(2**s -1 downto 0)(line_width-1 downto 0);
didn't work as expected. Only the rightmost element was changed. I 
didn't dig too deep into this problem and replaced that line by
1
TDinput <= temp2;
After that I saw a double delay on the temp signals (screenshot): the 
process obviously had to "run" twice to finally get the values assigned. 
So I put their assignment outside the process --> work done...

von Meli (Guest)


Rate this post
useful
not useful
Yes Lothar, you are right, the waveforms explain every thing and I'm 
justified with the reasoning. Thanks for your time. >:D<

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.