how to convert an integer to std_logic_vector using vhdl

Discussion in 'VHDL' started by ashwin, Nov 22, 2005.

  1. ashwin

    ashwin Guest

    Hello everyone,
    I am trying to divite a std_logic_vector by a std_logic_vector.
    So i converted both of them into integers and divided. But how do i
    convert back to std_logic_vector.

    1) Is the integer type or the division" / " synthesizable in xilinx

    2) if i use integer as my output port and when i download my code onto
    the fpga, does it convert back to the binary. If yes to how many bits.

    I appreciate if you could answer these questions

    ashwin, Nov 22, 2005
    1. Advertisements

  2. ashwin

    Andy Peters Guest

    Look up numeric_std -- this is the library that has the conversion
    functions you need. Do NOT use the obsolete std_logic_arith.
    The answer is in the Xilinx XST documentation.
    Integers are 32 bit values.

    Andy Peters, Nov 22, 2005
    1. Advertisements

  3. Andy Peters wrote:

    Full ack.

    my_int_u<=to_integer( unsigned(my_std_logic_vector) );
    my_int_s<=to_integer( signed(my_std_logic_vector) );

    Synthesis tools may be able to eliminate unneeded bits, IF it is clear
    to the tool. Therefore it is better to specify a "range" fo integers.

    In general it is not a good idea to use integers for (top level) ports,
    because often synthesis tools are configured to convert avery port
    signal to std_(u)logic_vector, because in reality you need a vector type
    for ports.

    Ralf Hildebrandt, Nov 22, 2005
  4. Jaakko Varteva, Nov 25, 2005
  5. ashwin

    Andy Peters Guest

    Indeed, that's exactly what I do ... it's very helpful during
    simulation, as the tools will complain if you try to assign an
    out-of-range value.

    The synthesizer simply lops off whatever bits are not needed, and it
    all works well.
    I never use integers as ports, but I've used (numeric_std's) unsigned
    and signed (both of which are really std_logic_vectors in a different
    dress, anyways) as ports. A big downside to using ranged integers or
    naturals as ports is unsigned and signed can be assigned 'X' and 'Z'
    whereas integers cannot. This is very convenient when your inputs are
    from an ADC whose outputs can be tristated and you're doing math on
    these values. Saves a conversion.

    Andy Peters, Nov 28, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.