FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-28-2009, 12:35 AM
alomar
Guest
 
Posts: n/a
Default VHDL process and function problem

hi all,

I have a vhdl process question. For a vector 'x', I want to derive its
unary or-reduction value, so I just write the following codes.
Strangely, it doesn't work. So I transformed it to a function version
which is proved to be correct.
My question is what is the difference between these two methods.
Thanks for your answering.

-----------------------------------------------------------------------
signal x : std_logic_vector(10 downto 0);

process(x)
variable result : std_logic :='0';
begin
for i in x'RANGE loop
result := result or x(i);
end loop;
or_reduce_x <= result;
end process;
-------------------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 07-28-2009, 01:16 AM
Mike Treseler
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

alomar wrote:
> hi all,
>
> I have a vhdl process question. For a vector 'x', I want to derive its
> unary or-reduction value, so I just write the following codes.
> Strangely, it doesn't work. So I transformed it to a function version
> which is proved to be correct.
> My question is what is the difference between these two methods.
> Thanks for your answering.
>
> -----------------------------------------------------------------------
> signal x : std_logic_vector(10 downto 0);
>
> process(x)
> variable result : std_logic :='0';
> begin
> for i in x'RANGE loop
> result := result or x(i);
> end loop;
> or_reduce_x <= result;
> end process;
> -------------------------------------------------------------------------


I expect you want a function, not a process, to form the value.
Show the or_reduce_x declaration.
What is driving X?

-- Mike Treseler
Reply With Quote
  #3 (permalink)  
Old 07-28-2009, 02:15 AM
alomar
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

On 7月28日, 上午7時16分, Mike Treseler <mtrese...@gmail.com> wrote:
> alomar wrote:
> > hi all,

>
> > I have a vhdl process question. For a vector 'x', I want to derive its
> > unary or-reduction value, so I just write the following codes.
> > Strangely, it doesn't work. So I transformed it to a function version
> > which is proved to be correct.
> > My question is what is the difference between these two methods.
> > Thanks for your answering.

>
> > -----------------------------------------------------------------------
> > signal x : std_logic_vector(10 downto 0);

>
> > process(x)
> > * * variable result : std_logic :='0';
> > begin
> > * * for i in x'RANGE loop
> > * * * * result := result or x(i);
> > * * end loop;
> > * * or_reduce_x <= result;
> > end process;
> > -------------------------------------------------------------------------

>
> I expect you want a function, not a process, to form the value.
> Show the or_reduce_x declaration.
> What is driving X?
>
> * *-- Mike Treseler



Er... Actually, I have on idea what you mean. The vector 'x' is driven
by some combinaional subcircuit and
or_reduce_x is a signal of type std_logic

signal or_reduce_x : std_logic;

When I sim the process above, the or_reduce_x always has some
miscellaneous value, such as 'X','U'...
I just don't know why.
Reply With Quote
  #4 (permalink)  
Old 07-28-2009, 09:16 AM
Michael Roland
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

alomar wrote:
> -----------------------------------------------------------------------
> signal x : std_logic_vector(10 downto 0);
>
> process(x)
> variable result : std_logic :='0';
> begin
> for i in x'RANGE loop
> result := result or x(i);
> end loop;
> or_reduce_x <= result;
> end process;
> -------------------------------------------------------------------------


The difference to the function variant

function or_reduce (v : in std_ulogic_vector) return std_ulogic is
variable result : std_ulogic := '0';
begin
for i in v'RANGE loop
result := result or v(i);
end loop;
return result;
end function or_reduce;

is the initialization of the variable result. While result is
initialized at every execution of the function, with the process variant
it is only initialized at the first run of the process.

Thus, with your process variant you accumulate all the previous values
of result.

Michael Roland
Reply With Quote
  #5 (permalink)  
Old 07-28-2009, 09:17 AM
Michael Roland
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

alomar wrote:
> -----------------------------------------------------------------------
> signal x : std_logic_vector(10 downto 0);
>
> process(x)
> variable result : std_logic :='0';
> begin
> for i in x'RANGE loop
> result := result or x(i);
> end loop;
> or_reduce_x <= result;
> end process;
> -------------------------------------------------------------------------


The difference to the function variant

function or_reduce (v : in std_ulogic_vector) return std_ulogic is
variable result : std_ulogic := '0';
begin
for i in v'RANGE loop
result := result or v(i);
end loop;
return result;
end function or_reduce;

is the initialization of the variable result. While result is
initialized at every execution of the function, with the process variant
it is only initialized at the first run of the process.

Thus, with your process variant you accumulate all the previous values
of result.

Michael Roland
Reply With Quote
  #6 (permalink)  
Old 07-28-2009, 02:32 PM
Enes Erdin
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

On 28 Temmuz, 10:17, Michael Roland <rolandmich...@hotmail.com> wrote:
> alomar wrote:
> > -----------------------------------------------------------------------
> > signal x : std_logic_vector(10 downto 0);

>
> > process(x)
> > * * variable result : std_logic :='0';
> > begin
> > * * for i in x'RANGE loop
> > * * * * result := result or x(i);
> > * * end loop;
> > * * or_reduce_x <= result;
> > end process;
> > -------------------------------------------------------------------------

>
> The difference to the function variant
>
> * function or_reduce (v : in std_ulogic_vector) return std_ulogic is
> * * variable result : std_ulogic := '0';
> * begin
> * * for i in v'RANGE loop
> * * * result := result or v(i);
> * * end loop;
> * * return result;
> * end function or_reduce;
>
> is the initialization of the variable result. While result is
> initialized at every execution of the function, with the process variant
> it is only initialized at the first run of the process.
>
> Thus, with your process variant you accumulate all the previous values
> of result.
>
> Michael Roland


That is true. In the process form, trying this will hopefully fix the
problem.

-----------------------------------------------------------------------
signal x : std_logic_vector(10 downto 0);

process(x)
variable result : std_logic :='0';
begin
result := x(0);--<--
for i in x'RANGE loop
result := result or x(i);
end loop;
or_reduce_x <= result;
end process;
-------------------------------------------------------------------------
Reply With Quote
  #7 (permalink)  
Old 07-28-2009, 07:48 PM
Andy
Guest
 
Posts: n/a
Default Re: VHDL process and function problem

On Jul 28, 7:32*am, Enes Erdin <eneser...@gmail.com> wrote:
>
> That is true. In the process form, trying this will hopefully fix the
> problem.
>
> -----------------------------------------------------------------------
> signal x : std_logic_vector(10 downto 0);
>
> process(x)
> * * variable result : std_logic :='0';
> begin
> * * result := x(0);--<--
> * * for i in x'RANGE loop
> * * * * result := result or x(i);
> * * end loop;
> * * or_reduce_x <= result;
> end process;


Note that this implementation, while logically correct in the final
result, OR's X(0) twice. Furthermore, by specifically referencing X
(0), it is dependent upon X'range being defined to include the index
element 0, which might not be the case for all applications. Better to
just initialize result to '0' instead.

For reusability (i.e. the ability to include in a package) it is best
if this is implemented as a function, even though the attempted
implementation as a process does illuminate subtle differences between
initializations in functions and processes.

Whether implemented as an entity/architecture (with an unconstrained
input port) or as a function, it is important to try to handle non-
normal cases (such as vectors not defined with the usual "N downto 0"
range) in reusable code. Sometimes declaring a local variable (or
signal) with the range (x'length - 1 downto 0), and copying the input
into it is required.

Andy
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
function/process to generate sine and cosine wave FPGA VHDL 15 02-09-2008 03:21 PM
function/process to generate sine and cosine wave FPGA FPGA 15 02-09-2008 03:21 PM
doubt on VHDL process [email protected] VHDL 2 09-21-2006 10:25 AM
Process Statements in VHDL samsky electronique VHDL 2 05-26-2005 12:54 PM
Karhunen-Loeve Expansion of a Wiener Process and Eigenvalues/Eigenfunctionsof a Function Randy Yates DSP 11 12-19-2003 06:16 AM


All times are GMT +1. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved