how to convert signal value to integer

Discussion in 'VHDL' started by Frank van Eijkelenburg, Jul 24, 2003.

  1. Hi,

    I'm new to VHDL and try to make some simple programs. Below I try to make an
    entity that gives the contents of a specified address at the databus.
    However, the compiler gives the following error:

    # ERROR: C:/project/VHDL/project/sram/sram.vhd(58): Type error in variable
    address. Needed type integer.

    So the question is: how can I convert the value present at the address bus
    to an integer? Or is there a better way to get this working??

    TIA,
    Frank

    entity sram is
    port(chip_enable : in bit;
    output_enable : in bit;
    address : in bit_vector (3 downto 0);
    data : out std_logic_vector (3 downto 0));
    end sram;

    architecture behaviour of sram is
    constant sram_size : Integer := 15;
    type sram_mem is array (0 to sram_size) of std_logic_vector (0 to 3);
    signal memory : sram_mem;

    begin
    get_data : process(address)
    begin
    if (chip_enable = '0' and output_enable = '0') then
    -- get data from selected address
    data <= memory(address);
    else
    data <= (others => 'Z');
    end if;
    end process;
    end behaviour;
    Frank van Eijkelenburg, Jul 24, 2003
    #1
    1. Advertising

  2. > So the question is: how can I convert the value present at the address bus
    > to an integer? Or is there a better way to get this working??


    Use numeric_std from the IEEE library. You'll end up with something like:

    data <= to_integer( unsigned( memory(address) ) );

    Regards,

    Pieter Hulshoff
    Pieter Hulshoff, Jul 24, 2003
    #2
    1. Advertising

  3. Frank van Eijkelenburg wrote:
    > Hi,
    >
    > I'm new to VHDL and try to make some simple programs. Below I try to make an
    > entity that gives the contents of a specified address at the databus.
    > However, the compiler gives the following error:


    For a related example see:


    http://groups.google.com/groups?q=vhdl test_oe_demo


    -- Mike Treseler
    Mike Treseler, Jul 24, 2003
    #3
  4. Frank van Eijkelenburg

    Pedro Claro Guest

    what about conv_integer or to_integer?

    Pedro Claro


    "Frank van Eijkelenburg" <> wrote in message news:<3f1ff79e$0$133$>...
    > Hi,
    >
    > I'm new to VHDL and try to make some simple programs. Below I try to make an
    > entity that gives the contents of a specified address at the databus.
    > However, the compiler gives the following error:
    >
    > # ERROR: C:/project/VHDL/project/sram/sram.vhd(58): Type error in variable
    > address. Needed type integer.
    >
    > So the question is: how can I convert the value present at the address bus
    > to an integer? Or is there a better way to get this working??
    >
    > TIA,
    > Frank
    >
    > entity sram is
    > port(chip_enable : in bit;
    > output_enable : in bit;
    > address : in bit_vector (3 downto 0);
    > data : out std_logic_vector (3 downto 0));
    > end sram;
    >
    > architecture behaviour of sram is
    > constant sram_size : Integer := 15;
    > type sram_mem is array (0 to sram_size) of std_logic_vector (0 to 3);
    > signal memory : sram_mem;
    >
    > begin
    > get_data : process(address)
    > begin
    > if (chip_enable = '0' and output_enable = '0') then
    > -- get data from selected address
    > data <= memory(address);
    > else
    > data <= (others => 'Z');
    > end if;
    > end process;
    > end behaviour;
    Pedro Claro, Jul 24, 2003
    #4
  5. Frank van Eijkelenburg

    Yttrium Guest

    why not using a function to convert the signal to int, something like

    function vec2int (vec1: std_logic_vector) return integer is
    variable retval: integer := 0;
    alias vec: std_logic_vector(vec1'length-1 downto 0) is vec1;
    begin
    for i in vec'high downto 1 loop
    if (vec(i)='1') then
    retval:=(retval+1)*2;
    else retval:=retval*2;
    end if;
    end loop;
    if (vec(0)='1') then --we brengen de laatste bit in rekening door
    eventueel op te tellen of niet!
    retval:=retval+1;
    end if;
    return retval;
    end vec2int;

    and then use it like this: data <= memory(vec2int(address));
    "Frank van Eijkelenburg" <> wrote in message
    news:3f1ff79e$0$133$...
    > Hi,
    >
    > I'm new to VHDL and try to make some simple programs. Below I try to make

    an
    > entity that gives the contents of a specified address at the databus.
    > However, the compiler gives the following error:
    >
    > # ERROR: C:/project/VHDL/project/sram/sram.vhd(58): Type error in variable
    > address. Needed type integer.
    >
    > So the question is: how can I convert the value present at the address bus
    > to an integer? Or is there a better way to get this working??
    >
    > TIA,
    > Frank
    >
    > entity sram is
    > port(chip_enable : in bit;
    > output_enable : in bit;
    > address : in bit_vector (3 downto 0);
    > data : out std_logic_vector (3 downto 0));
    > end sram;
    >
    > architecture behaviour of sram is
    > constant sram_size : Integer := 15;
    > type sram_mem is array (0 to sram_size) of std_logic_vector (0 to 3);
    > signal memory : sram_mem;
    >
    > begin
    > get_data : process(address)
    > begin
    > if (chip_enable = '0' and output_enable = '0') then
    > -- get data from selected address
    > data <= memory(address);
    > else
    > data <= (others => 'Z');
    > end if;
    > end process;
    > end behaviour;
    >
    >
    Yttrium, Jul 25, 2003
    #5
  6. Frank van Eijkelenburg

    vipinlal

    Joined:
    Feb 25, 2010
    Messages:
    38
    i think conv_integer should work in your case.
    signal a : std_logic_vector (11 downto 0);
    signal b: integer;
    b<=conv_integer(a);

    ----------------------------------------------
    vhdlguru.blogspot.com
    vipinlal, Mar 5, 2010
    #6
    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. les ander
    Replies:
    4
    Views:
    883
    wes weston
    Oct 5, 2004
  2. Michael Pronath
    Replies:
    1
    Views:
    1,166
    Diez B. Roggisch
    Jan 3, 2005
  3. Jack Orenstein

    threading.Thread vs. signal.signal

    Jack Orenstein, Sep 18, 2005, in forum: Python
    Replies:
    0
    Views:
    464
    Jack Orenstein
    Sep 18, 2005
  4. Robben
    Replies:
    14
    Views:
    563
    Old Wolf
    Dec 27, 2005
  5. Guffi
    Replies:
    2
    Views:
    548
    Guffi
    Sep 13, 2007
Loading...

Share This Page