Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > how to convert signal value to integer

Reply
Thread Tools

how to convert signal value to integer

 
 
Frank van Eijkelenburg
Guest
Posts: n/a
 
      07-24-2003
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(5: 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;


 
Reply With Quote
 
 
 
 
Pieter Hulshoff
Guest
Posts: n/a
 
      07-24-2003
> 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

 
Reply With Quote
 
 
 
 
Mike Treseler
Guest
Posts: n/a
 
      07-24-2003


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

 
Reply With Quote
 
Pedro Claro
Guest
Posts: n/a
 
      07-24-2003
what about conv_integer or to_integer?

Pedro Claro


"Frank van Eijkelenburg" <(E-Mail Removed)> wrote in message news:<3f1ff79e$0$133$(E-Mail Removed)>.. .
> 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(5: 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;

 
Reply With Quote
 
Yttrium
Guest
Posts: n/a
 
      07-25-2003
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" <(E-Mail Removed)> wrote in message
news:3f1ff79e$0$133$(E-Mail Removed)...
> 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(5: 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;
>
>



 
Reply With Quote
 
vipinlal vipinlal is offline
Member
Join Date: Feb 2010
Posts: 39
 
      03-05-2010
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
 
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
how to convert integer to signal value Guffi VHDL 2 09-13-2007 02:46 PM
Aside from delta cycles and/or resolution functions, how can the effective value of a signal differ from a driving signal of its? Colin Paul Gloster VHDL 0 01-11-2007 01:31 PM
integer int i; *i++ and ++*i have a different integer value after the increment Robben C++ 14 12-27-2005 03:43 AM
how to convert "BigInteger" into "Integer"? how to print out a BigInteger binary value? nick Java 0 10-26-2004 08:18 AM
convert scientific integer to normal integer les ander Python 4 10-05-2004 04:26 PM



Advertisments