incrementing unsigned array

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Visit site
Activity points
18,302
I have a custom type that's defined as follows:
Code:
type unconstrained_array is array ( natural range <> ) of unsigned ;

signal x is declared as follows:
signal x : unconstrained_array ;

I want to write a loop that assignes to x an array of incrementing unsigned numbers as follows:

"0000"
"0001"
"0010"
.
.
.
"1111"

However, becuse x is an unconstrained array, I want the code to be generic and except any width and depth of x.
This is what I wrote so far:

Code:
for index in x ' range 
loop
x ( index ) <= to_unsigned ( index , ( x ' length ) ) ;
end loop ;

What do you think? Anything I should fix?
 

First of all, x cannot be declared like this:
signal x : unconstrained_array ;

It needs to have it's two dimensions defined at declaration:
something like this:

signal x : unconstrained_array(7 downto 0)(7 downto 0);

When you have got over this hurdle, the for loop you have should work this this minor modification:

x ( index ) <= to_unsigned ( index , ( x(index)'length ) ) ;
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
This is what I wrote:

Code:
running_address : process ( all ) is 
begin
  for index in x ' range
  [COLOR="#FF0000"]loop[/COLOR] 
    x ( index ) <= to_unsigned ( index , ( x ( index ) ' length ) ) ; 
  end loop ;	
end process running_address ;

However, this code causes modelsim to freeze.
Pressing the break key releases the freeze after a long delay with a note that points to the line marked in red)
Rewriting the code in a non generic way, doesn't cause a problem.

Any ideas?
 

because you put process(all) this process will be re-run when ANY signal changes. This will probably slow modelsim to a crawl.

This isnt really a process - you dont have anything that would cause a change in X. Everything is constant, so why is it in a process?
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…