Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > conv_integer simulation whining in ISE

Reply
Thread Tools

conv_integer simulation whining in ISE

 
 
nfirtaps
Guest
Posts: n/a
 
      11-16-2006
I have a circular buffer so my read and write index pointers need to
wrap around to the first index in the circular buffer when incremented
past the last index in the circular buffer. In order to index my
circular buffer I do

circular_buffer(conv_integer(write_index)) <= write_data;
write_index <= write_index + 1;

or

read_data <= circular_buffer(conv_integer(read_index));
read_index <= read_index + 1;

This synthesizes fine but I want read_index and write_index to be in a
modulo ring and wrap around when incremented. The simulator (ISE
Simulator Lite) complains about this treatment. It says Index 16 out
of bound 15 downto 0. I have my read and write indexes as
std_logic_vector(15 downto 0).

How do I work around this?

 
Reply With Quote
 
 
 
 
Ray Andraka
Guest
Posts: n/a
 
      11-16-2006
nfirtaps wrote:

> I have a circular buffer so my read and write index pointers need to
> wrap around to the first index in the circular buffer when incremented
> past the last index in the circular buffer. In order to index my
> circular buffer I do
>
> circular_buffer(conv_integer(write_index)) <= write_data;
> write_index <= write_index + 1;
>
> or
>
> read_data <= circular_buffer(conv_integer(read_index));
> read_index <= read_index + 1;
>
> This synthesizes fine but I want read_index and write_index to be in a
> modulo ring and wrap around when incremented. The simulator (ISE
> Simulator Lite) complains about this treatment. It says Index 16 out
> of bound 15 downto 0. I have my read and write indexes as
> std_logic_vector(15 downto 0).
>
> How do I work around this?
>


First, use ieee.numeric_std rather than std_logic.unsigned.
ieee.numeric_std is a real standard, unlike the std_logic libraries
which are vendor specific. Numeric_std also uses the same library for
signed and unsigned, so there are no library function name issues that
would otherwise have to be resolved with extensions.

Then:

circular_buffer(to_integer(unsigned(write_index))) <= write_data;
write_index <= (write_index + 1) mod 2**write_index_bits;

mod is synthesizable as long as the modulo is a constant and is an
integer power of 2.
 
Reply With Quote
 
 
 
 
Mike Treseler
Guest
Posts: n/a
 
      11-16-2006
nfirtaps wrote:
> I have a circular buffer so my read and write index pointers need to
> wrap around to the first index in the circular buffer when incremented
> past the last index in the circular buffer.
> How do I work around this?


Unsigned type can be used inside the process
to roll over as you wish with std_logic_vecotor
type on the ports:

subtype ptr_type is unsigned(add_length-1 downto 0);
-- unsigned wraps
signal pop_head_ptr : ptr_type; -- both _ptr must init same
signal push_tail_ptr : ptr_type;
-- each counts up appropriate cycles

see sync_fifo.vhd here for details:

http://home.comcast.net/~mike_treseler/
 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      11-16-2006
Or we can dispense with the vector/integer conversions, and use integer
signals to begin with.

Note that integer math does not roll over automatically, you have to
tell it what you want it to do (mod operator).

constant ndx_size : integer := 8;
subtype ndx_t is integer range 0 to 2**ndx_size - 1;
type buffer_t is array (ndx_t) of std_logic_vector(data_size - 1 downto
0);
signal circular_buffer : buffer_t;
signal rd_ndx, wr_ndx : ndx_t;
....

circular_buffer(wr_ndx) <= write_data;
wr_ndx <= (wr_ndx + 1) mod ndx_t'high;
....
read_data<= circular_buffer(rd_ndx);
rd_ndx <= (rd_ndx + 1) mod ndx_t'high;

And even with the extra mod operations, the integer signals will
simulate _much_ faster.

Andy

Mike Treseler wrote:
> nfirtaps wrote:
> > I have a circular buffer so my read and write index pointers need to
> > wrap around to the first index in the circular buffer when incremented
> > past the last index in the circular buffer.
> > How do I work around this?

>
> Unsigned type can be used inside the process
> to roll over as you wish with std_logic_vecotor
> type on the ports:
>
> subtype ptr_type is unsigned(add_length-1 downto 0);
> -- unsigned wraps
> signal pop_head_ptr : ptr_type; -- both _ptr must init same
> signal push_tail_ptr : ptr_type;
> -- each counts up appropriate cycles
>
> see sync_fifo.vhd here for details:
>
> http://home.comcast.net/~mike_treseler/


 
Reply With Quote
 
nfirtaps
Guest
Posts: n/a
 
      11-16-2006
Guys, I have tried all 3 of your recommendations to no avail. Let me
show you what I have exactly, here is an example of what Mike
Tresseler recommended. The other two methods have the same result.
Thus, I must have something logically wrong. Here I am using
unsigned's. ISE is very picky what type I index the circular buffer
with.

constant index_size : integer := 16;
subtype index is unsigned(index_size-1 downto 0);
type memory_type is array(index_size-1 downto 0) of
std_logic_vector(index_size-1 downto 0);

signal circ_buff : memory_type;
signal write_index : index;
signal read_index : index;

.....
-- in a process on the rising edge of a clock ....
circ_buff(conv_integer(write_index)) <= ddc_data;
write_index <= write_index+1;
.....
-- in a process on the rising edge of a clock ....
data_out <= circ_buff(conv_integer(read_index));
read_index <= read_index+1;

The simulator says the following on all 3 methods :

Index 16 out of bound 15 downto 0.



Andy wrote:
> Or we can dispense with the vector/integer conversions, and use integer
> signals to begin with.
>
> Note that integer math does not roll over automatically, you have to
> tell it what you want it to do (mod operator).
>
> constant ndx_size : integer := 8;
> subtype ndx_t is integer range 0 to 2**ndx_size - 1;
> type buffer_t is array (ndx_t) of std_logic_vector(data_size - 1 downto
> 0);
> signal circular_buffer : buffer_t;
> signal rd_ndx, wr_ndx : ndx_t;
> ...
>
> circular_buffer(wr_ndx) <= write_data;
> wr_ndx <= (wr_ndx + 1) mod ndx_t'high;
> ...
> read_data<= circular_buffer(rd_ndx);
> rd_ndx <= (rd_ndx + 1) mod ndx_t'high;
>
> And even with the extra mod operations, the integer signals will
> simulate _much_ faster.
>
> Andy
>
> Mike Treseler wrote:
> > nfirtaps wrote:
> > > I have a circular buffer so my read and write index pointers need to
> > > wrap around to the first index in the circular buffer when incremented
> > > past the last index in the circular buffer.
> > > How do I work around this?

> >
> > Unsigned type can be used inside the process
> > to roll over as you wish with std_logic_vecotor
> > type on the ports:
> >
> > subtype ptr_type is unsigned(add_length-1 downto 0);
> > -- unsigned wraps
> > signal pop_head_ptr : ptr_type; -- both _ptr must init same
> > signal push_tail_ptr : ptr_type;
> > -- each counts up appropriate cycles
> >
> > see sync_fifo.vhd here for details:
> >
> > http://home.comcast.net/~mike_treseler/


 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      11-16-2006
If index has index_size bits, then the buffer needs (2**index_size)
elements (2**index_size -1 downto 0). You are overflowing the index to
the buffer, not the index counts themselves.

Andy


nfirtaps wrote:
> Guys, I have tried all 3 of your recommendations to no avail. Let me
> show you what I have exactly, here is an example of what Mike
> Tresseler recommended. The other two methods have the same result.
> Thus, I must have something logically wrong. Here I am using
> unsigned's. ISE is very picky what type I index the circular buffer
> with.
>
> constant index_size : integer := 16;
> subtype index is unsigned(index_size-1 downto 0);
> type memory_type is array(index_size-1 downto 0) of
> std_logic_vector(index_size-1 downto 0);
>
> signal circ_buff : memory_type;
> signal write_index : index;
> signal read_index : index;
>
> ....
> -- in a process on the rising edge of a clock ....
> circ_buff(conv_integer(write_index)) <= ddc_data;
> write_index <= write_index+1;
> ....
> -- in a process on the rising edge of a clock ....
> data_out <= circ_buff(conv_integer(read_index));
> read_index <= read_index+1;
>
> The simulator says the following on all 3 methods :
>
> Index 16 out of bound 15 downto 0.
>
>
>
> Andy wrote:
> > Or we can dispense with the vector/integer conversions, and use integer
> > signals to begin with.
> >
> > Note that integer math does not roll over automatically, you have to
> > tell it what you want it to do (mod operator).
> >
> > constant ndx_size : integer := 8;
> > subtype ndx_t is integer range 0 to 2**ndx_size - 1;
> > type buffer_t is array (ndx_t) of std_logic_vector(data_size - 1 downto
> > 0);
> > signal circular_buffer : buffer_t;
> > signal rd_ndx, wr_ndx : ndx_t;
> > ...
> >
> > circular_buffer(wr_ndx) <= write_data;
> > wr_ndx <= (wr_ndx + 1) mod ndx_t'high;
> > ...
> > read_data<= circular_buffer(rd_ndx);
> > rd_ndx <= (rd_ndx + 1) mod ndx_t'high;
> >
> > And even with the extra mod operations, the integer signals will
> > simulate _much_ faster.
> >
> > Andy
> >
> > Mike Treseler wrote:
> > > nfirtaps wrote:
> > > > I have a circular buffer so my read and write index pointers need to
> > > > wrap around to the first index in the circular buffer when incremented
> > > > past the last index in the circular buffer.
> > > > How do I work around this?
> > >
> > > Unsigned type can be used inside the process
> > > to roll over as you wish with std_logic_vecotor
> > > type on the ports:
> > >
> > > subtype ptr_type is unsigned(add_length-1 downto 0);
> > > -- unsigned wraps
> > > signal pop_head_ptr : ptr_type; -- both _ptr must init same
> > > signal push_tail_ptr : ptr_type;
> > > -- each counts up appropriate cycles
> > >
> > > see sync_fifo.vhd here for details:
> > >
> > > http://home.comcast.net/~mike_treseler/


 
Reply With Quote
 
nfirtaps
Guest
Posts: n/a
 
      11-16-2006
Ah, for some reason I thought at array (array(n downto 0)) has 2**n-1
elements, oops. Thanks a ton for all the replies they helped so much.

Lloyd


Andy wrote:
> If index has index_size bits, then the buffer needs (2**index_size)
> elements (2**index_size -1 downto 0). You are overflowing the index to
> the buffer, not the index counts themselves.
>
> Andy
>
>
> nfirtaps wrote:
> > Guys, I have tried all 3 of your recommendations to no avail. Let me
> > show you what I have exactly, here is an example of what Mike
> > Tresseler recommended. The other two methods have the same result.
> > Thus, I must have something logically wrong. Here I am using
> > unsigned's. ISE is very picky what type I index the circular buffer
> > with.
> >
> > constant index_size : integer := 16;
> > subtype index is unsigned(index_size-1 downto 0);
> > type memory_type is array(index_size-1 downto 0) of
> > std_logic_vector(index_size-1 downto 0);
> >
> > signal circ_buff : memory_type;
> > signal write_index : index;
> > signal read_index : index;
> >
> > ....
> > -- in a process on the rising edge of a clock ....
> > circ_buff(conv_integer(write_index)) <= ddc_data;
> > write_index <= write_index+1;
> > ....
> > -- in a process on the rising edge of a clock ....
> > data_out <= circ_buff(conv_integer(read_index));
> > read_index <= read_index+1;
> >
> > The simulator says the following on all 3 methods :
> >
> > Index 16 out of bound 15 downto 0.
> >
> >
> >
> > Andy wrote:
> > > Or we can dispense with the vector/integer conversions, and use integer
> > > signals to begin with.
> > >
> > > Note that integer math does not roll over automatically, you have to
> > > tell it what you want it to do (mod operator).
> > >
> > > constant ndx_size : integer := 8;
> > > subtype ndx_t is integer range 0 to 2**ndx_size - 1;
> > > type buffer_t is array (ndx_t) of std_logic_vector(data_size - 1 downto
> > > 0);
> > > signal circular_buffer : buffer_t;
> > > signal rd_ndx, wr_ndx : ndx_t;
> > > ...
> > >
> > > circular_buffer(wr_ndx) <= write_data;
> > > wr_ndx <= (wr_ndx + 1) mod ndx_t'high;
> > > ...
> > > read_data<= circular_buffer(rd_ndx);
> > > rd_ndx <= (rd_ndx + 1) mod ndx_t'high;
> > >
> > > And even with the extra mod operations, the integer signals will
> > > simulate _much_ faster.
> > >
> > > Andy
> > >
> > > Mike Treseler wrote:
> > > > nfirtaps wrote:
> > > > > I have a circular buffer so my read and write index pointers need to
> > > > > wrap around to the first index in the circular buffer when incremented
> > > > > past the last index in the circular buffer.
> > > > > How do I work around this?
> > > >
> > > > Unsigned type can be used inside the process
> > > > to roll over as you wish with std_logic_vecotor
> > > > type on the ports:
> > > >
> > > > subtype ptr_type is unsigned(add_length-1 downto 0);
> > > > -- unsigned wraps
> > > > signal pop_head_ptr : ptr_type; -- both _ptr must init same
> > > > signal push_tail_ptr : ptr_type;
> > > > -- each counts up appropriate cycles
> > > >
> > > > see sync_fifo.vhd here for details:
> > > >
> > > > http://home.comcast.net/~mike_treseler/


 
Reply With Quote
 
nfirtaps
Guest
Posts: n/a
 
      11-16-2006
Ah, for some reason I thought at array (array(n downto 0)) has 2**n-1
elements, oops. Thanks a ton for all the replies they helped so much.

Lloyd


Andy wrote:
> If index has index_size bits, then the buffer needs (2**index_size)
> elements (2**index_size -1 downto 0). You are overflowing the index to
> the buffer, not the index counts themselves.
>
> Andy
>
>
> nfirtaps wrote:
> > Guys, I have tried all 3 of your recommendations to no avail. Let me
> > show you what I have exactly, here is an example of what Mike
> > Tresseler recommended. The other two methods have the same result.
> > Thus, I must have something logically wrong. Here I am using
> > unsigned's. ISE is very picky what type I index the circular buffer
> > with.
> >
> > constant index_size : integer := 16;
> > subtype index is unsigned(index_size-1 downto 0);
> > type memory_type is array(index_size-1 downto 0) of
> > std_logic_vector(index_size-1 downto 0);
> >
> > signal circ_buff : memory_type;
> > signal write_index : index;
> > signal read_index : index;
> >
> > ....
> > -- in a process on the rising edge of a clock ....
> > circ_buff(conv_integer(write_index)) <= ddc_data;
> > write_index <= write_index+1;
> > ....
> > -- in a process on the rising edge of a clock ....
> > data_out <= circ_buff(conv_integer(read_index));
> > read_index <= read_index+1;
> >
> > The simulator says the following on all 3 methods :
> >
> > Index 16 out of bound 15 downto 0.
> >
> >
> >
> > Andy wrote:
> > > Or we can dispense with the vector/integer conversions, and use integer
> > > signals to begin with.
> > >
> > > Note that integer math does not roll over automatically, you have to
> > > tell it what you want it to do (mod operator).
> > >
> > > constant ndx_size : integer := 8;
> > > subtype ndx_t is integer range 0 to 2**ndx_size - 1;
> > > type buffer_t is array (ndx_t) of std_logic_vector(data_size - 1 downto
> > > 0);
> > > signal circular_buffer : buffer_t;
> > > signal rd_ndx, wr_ndx : ndx_t;
> > > ...
> > >
> > > circular_buffer(wr_ndx) <= write_data;
> > > wr_ndx <= (wr_ndx + 1) mod ndx_t'high;
> > > ...
> > > read_data<= circular_buffer(rd_ndx);
> > > rd_ndx <= (rd_ndx + 1) mod ndx_t'high;
> > >
> > > And even with the extra mod operations, the integer signals will
> > > simulate _much_ faster.
> > >
> > > Andy
> > >
> > > Mike Treseler wrote:
> > > > nfirtaps wrote:
> > > > > I have a circular buffer so my read and write index pointers need to
> > > > > wrap around to the first index in the circular buffer when incremented
> > > > > past the last index in the circular buffer.
> > > > > How do I work around this?
> > > >
> > > > Unsigned type can be used inside the process
> > > > to roll over as you wish with std_logic_vecotor
> > > > type on the ports:
> > > >
> > > > subtype ptr_type is unsigned(add_length-1 downto 0);
> > > > -- unsigned wraps
> > > > signal pop_head_ptr : ptr_type; -- both _ptr must init same
> > > > signal push_tail_ptr : ptr_type;
> > > > -- each counts up appropriate cycles
> > > >
> > > > see sync_fifo.vhd here for details:
> > > >
> > > > http://home.comcast.net/~mike_treseler/


 
Reply With Quote
 
Ray Andraka
Guest
Posts: n/a
 
      11-17-2006
nfirtaps wrote:

> Guys, I have tried all 3 of your recommendations to no avail. Let me
> show you what I have exactly, here is an example of what Mike
> Tresseler recommended. The other two methods have the same result.
> Thus, I must have something logically wrong. Here I am using
> unsigned's. ISE is very picky what type I index the circular buffer
> with.
>
> constant index_size : integer := 16;
> subtype index is unsigned(index_size-1 downto 0);
> type memory_type is array(index_size-1 downto 0) of
> std_logic_vector(index_size-1 downto 0);
>
> signal circ_buff : memory_type;
> signal write_index : index;
> signal read_index : index;
>
> ....
> -- in a process on the rising edge of a clock ....
> circ_buff(conv_integer(write_index)) <= ddc_data;
> write_index <= write_index+1;
> ....
> -- in a process on the rising edge of a clock ....
> data_out <= circ_buff(conv_integer(read_index));
> read_index <= read_index+1;
>
> The simulator says the following on all 3 methods :
>
> Index 16 out of bound 15 downto 0.
>


You need to use the mod operator or some conditional execution to keep
the index within the range 0 to 15.

read_index <= (read_index+1) mod 16;

will do it, as will:

read_index <= read_index+1;
if read_index > 15 then
read_index <= read_index - 16;

or
if read_index > 15 then
read_index <= 0;
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem with conv_integer ThWolf VHDL 2 12-15-2008 02:36 PM
conv_integer for unsigned value Clemens VHDL 9 07-14-2008 05:10 PM
CONV_INTEGER ERROR ted.franklin3@gmail.com VHDL 4 10-18-2006 10:41 PM
Error in FIFO Simulation ISE Xilinx nfirtaps VHDL 1 08-31-2006 05:17 PM
CONV_INTEGER problems Giox VHDL 3 02-13-2006 09:18 AM



Advertisments