conv_integer simulation whining in ISE

Discussion in 'VHDL' started by nfirtaps, Nov 16, 2006.

  1. nfirtaps

    nfirtaps Guest

    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?
    nfirtaps, Nov 16, 2006
    #1
    1. Advertising

  2. nfirtaps

    Ray Andraka Guest

    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.
    Ray Andraka, Nov 16, 2006
    #2
    1. Advertising

  3. 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/
    Mike Treseler, Nov 16, 2006
    #3
  4. nfirtaps

    Andy Guest

    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/
    Andy, Nov 16, 2006
    #4
  5. nfirtaps

    nfirtaps Guest

    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/
    nfirtaps, Nov 16, 2006
    #5
  6. nfirtaps

    Andy Guest

    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/
    Andy, Nov 16, 2006
    #6
  7. nfirtaps

    nfirtaps Guest

    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/
    nfirtaps, Nov 16, 2006
    #7
  8. nfirtaps

    nfirtaps Guest

    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/
    nfirtaps, Nov 16, 2006
    #8
  9. nfirtaps

    Ray Andraka Guest

    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;
    Ray Andraka, Nov 17, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giox

    CONV_INTEGER problems

    Giox, Feb 12, 2006, in forum: VHDL
    Replies:
    3
    Views:
    20,929
  2. =?ISO-8859-1?Q?G=E9rard_Talbot?=

    Whining and bitching about MSIE 6 CSS bugs and CSS support

    =?ISO-8859-1?Q?G=E9rard_Talbot?=, Jul 9, 2005, in forum: HTML
    Replies:
    0
    Views:
    410
    =?ISO-8859-1?Q?G=E9rard_Talbot?=
    Jul 9, 2005
  3. CONV_INTEGER ERROR

    , Oct 18, 2006, in forum: VHDL
    Replies:
    4
    Views:
    5,154
    Jim Lewis
    Oct 18, 2006
  4. Clemens

    conv_integer for unsigned value

    Clemens, Jul 8, 2008, in forum: VHDL
    Replies:
    9
    Views:
    4,140
    rickman
    Jul 14, 2008
  5. ThWolf

    A problem with conv_integer

    ThWolf, Dec 13, 2008, in forum: VHDL
    Replies:
    2
    Views:
    2,082
    ThWolf
    Dec 15, 2008
Loading...

Share This Page