Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21336 Discussions

Loop index overflow problem

Altera_Forum
Honored Contributor II
3,820 Views

Hi there, 

 

I've wrote a little VHDL program in Quartus II. 

I'd like to separate one big std_logic_vector into small fix-length std_logic_vectors 

and the compile told me that the index is out of range, very strange... 

 

source code: 

=================================================== 

load_p:process(i_clk,i_datain)  

variable p_count:integer range 0 to 8*8*i_width; --i_width is a constant 

variable p:std_logic_vector(i_width-1 downto 0);--buffer of one data 

begin 

p_count := 8*8*i_width-1; --counter for index 

for i in 0 to 63 loop 

p := datain(p_count downto p_count-i_width+1); --buffering 

(line 30) p_count := p_count-i_width; --get next line index 

end loop; 

 

end process; 

 

======================================================= 

the compiler says: 

 

Error (10528): VHDL error at df_loader_p.vhd(30): value "-1" is outside the target constraint range (0 to 512) 

 

Help me out , thx!!!:(
0 Kudos
21 Replies
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

very strange... 

--- Quote End ---  

The code does exactly what you have written.  

 

In the last iteration, it tries to decrement p_count from 7 to -1, although everything is finished. Instead of decrementing a variable, you may want to calculate the p_count value at the entry of each iteration.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

Another question - is this testbench code?

0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

The code does exactly what you have written.  

 

In the last iteration, it tries to decrement p_count from 7 to -1, although everything is finished. Instead of decrementing a variable, you may want to calculate the p_count value at the entry of each iteration. 

--- Quote End ---  

 

 

Hi, thx for reply, 

 

i don't really understand what is your suggestion means...you mean i have to unroll the iteration? 

 

and i think you'er right about the iteration , that after the "last" iteration (i=63), the i continue increasing to 64, like C language or any other program language, but with the entry constrain , the procedure in the iteration shouldn't be executed... 

 

i think i have to loose the constrain of the range of p_count to -1 to 8*8*i_width...
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

Another question - is this testbench code? 

--- Quote End ---  

 

 

no, it's a small single component in a big system
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

Or you could start Pcount at its upper bound and just change the datain extraction.

0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

no, it's a small single component in a big system 

--- Quote End ---  

 

 

Then your design is very flawed. It is not going to produce synchronous logic because you have not included the clock inside your process.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

Then your design is very flawed. It is not going to produce synchronous logic because you have not included the clock inside your process. 

--- Quote End ---  

 

 

:D, no ,i use two processes method, this is only the combinational part, i have deleted the sequential part...
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

ok, then i 've changed the P_count to increasing order, problem still... 

 

p_count := 0; --counter for index 

for i in 0 to 63 loop 

p := datain(p_count+i_width-1 downto p_count); --buffering 

p_count := p_count+i_width; --get next line index 

 

end loop; 

 

and the compiler says: 

 

Error (10528): VHDL error at df_loader_p.vhd(30): value "512" is outside the target constraint range (0 to 511) 

T.T
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

Ok - It was because you had included the clock in the sensitivity list and not used it - it is a common newbie mistake.

0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

You have changed the constraint range - in the origional code you posted : 

 

variable p_count:integer range 0 to 8*8*i_width; --i_width is a constant 

 

Which should give you 0 to 512.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

Ok - It was because you had included the clock in the sensitivity list and not used it - it is a common newbie mistake. 

--- Quote End ---  

 

 

i think at the synthesis phase, the compile actually add all the signals to the sensitive list.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

No - the synthesisor ignores the sensitivity list. It will warn you if there are signals missing from the list, but it makes no difference to the logic created.

0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

You have changed the constraint range - in the origional code you posted : 

 

variable p_count:integer range 0 to 8*8*i_width; --i_width is a constant 

 

Which should give you 0 to 512. 

--- Quote End ---  

 

 

that is because the iteration should stop at 511
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

How can it stop at 511 when you add 8 each time?

0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

How can it stop at 511 when you add 8 each time? 

--- Quote End ---  

 

 

because i only have 64 iterations, and started from 0, the last data bit range should be 504 to 511. 

i have ran this similar algorithm in C Code, the iteration stop at 511, no error appeared.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

int i,j; 

j=0; 

for(i=0;i<=63;i++){ 

printf("%d,%d,%d\n",i, j,j+7); 

j+=8; 

 

the last line of the output is 63,504,511
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

thats because j stops at 504, and you print j+7 

I dont see a p_count + 7 offset anywhere in your VHDL. 

 

You'll find that j actually finishes the loop on 512.
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

 

--- Quote Start ---  

thats because j stops at 504, and you print j+7 

I dont see a p_count + 7 offset anywhere in your VHDL. 

 

You'll find that j actually finishes the loop on 512. 

--- Quote End ---  

 

 

i wrote this, 

 

p := datain(p_count+i_width-1 downto p_count); --i_width=8, so this is my "p_count+7" 

p_count:=p_count+i_width;
0 Kudos
Altera_Forum
Honored Contributor II
1,676 Views

yes, and just like in the C, you have the extra p_count := p_count+i_width which pushes p_count to 512 as the loop exits. 

 

you have exactly the same thing with j. It ends the loop on 512.
0 Kudos
Altera_Forum
Honored Contributor II
1,542 Views

 

--- Quote Start ---  

yes, and just like in the C, you have the extra p_count := p_count+i_width which pushes p_count to 512 as the loop exits. 

 

you have exactly the same thing with j. It ends the loop on 512. 

--- Quote End ---  

 

 

ok, i understand, the iteration actually enter the overflow situation and then exit
0 Kudos
Reply