Generic range

A

ALuPin@web.de

Guest
Hi,

I am trying to do the following:

signal ls_test : unsigned(7 downto 0);


process(ls_test)
begin
if ls_test(7 downto 1) = "0000000" then
...
end if;
end process;


Now I want to have something like:

signal ls_test : unsigned(gWidth-1 downto 0);

process(ls_test)
begin
if ls_test = (ls_test'high downto ls_test'low +1 => '0') then
...
end if;
end process;

When compiling I get the following error:
"Operator "=" is not defined for such operands.

Can somebody share some light on it ?

Thank you.
Rgds, ALuPin
 
ALuPin@web.de a formulé la demande :
Hi,

I am trying to do the following:

signal ls_test : unsigned(7 downto 0);


process(ls_test)
begin
if ls_test(7 downto 1) = "0000000" then
...
end if;
end process;


Now I want to have something like:

signal ls_test : unsigned(gWidth-1 downto 0);

process(ls_test)
begin
if ls_test = (ls_test'high downto ls_test'low +1 => '0') then
...
end if;
end process;

When compiling I get the following error:
"Operator "=" is not defined for such operands.

Can somebody share some light on it ?

Thank you.
Rgds, ALuPin
Is this what you're trying to write ?

constant gWidth : positive := 8;
signal ls_test : unsigned(gWidth-1 downto 0);
Begin
process (ls_test)
begin
if ls_test (ls_test'high downto ls_test'low +1) = 0 then
report "done !";
end if;
end process;

Bert Cuzeau
 
ALuPin@web.de avait soumis l'idée :
Hi Bert,

not exactly.

Your solution works for

if ls_test = (ls_test'high downto ls_test'low +1 => '0') then

but not for

if ls_test = (ls_test'high downto ls_test'low +1 => '1') then

that is all the vector bits are '1'.

Rgds,
ALuPin
Then :

constant gWidth : positive :=8;
signal ls_test : signed(gWidth-1 downto 0) := (0=>'0', others=>'1');
Begin
process (ls_test)
begin
if ls_test (ls_test'high downto ls_test'low +1) = -1 then
report "all ones, LSB ignored !";
end if;
end process;
 
Hi Bert,

not exactly.

Your solution works for

if ls_test = (ls_test'high downto ls_test'low +1 => '0') then
but not for

if ls_test = (ls_test'high downto ls_test'low +1 => '1') then
that is all the vector bits are '1'.

Rgds,
ALuPin
 
On Mon, 30 Mar 2009 01:50:20 -0700 (PDT), "ALuPin@web.de" <ALuPin@web.de> wrote:

Hi,

Now I want to have something like:

signal ls_test : unsigned(gWidth-1 downto 0);

process(ls_test)
begin
if ls_test = (ls_test'high downto ls_test'low +1 => '0') then
...
end if;
end process;

When compiling I get the following error:
"Operator "=" is not defined for such operands.

Can somebody share some light on it ?
The RHS expression could match any number of visible types, from string to
std_logic_vector to signed to .... and "=" could be overloaded to handle any or
all of them.

The compiler can't possibly tell which of them you are aiming for.
Unlike some other languages, rather than silently landing you with the language
designer's arbitrary choice(*), VHDL reports and lets (i.e. makes) YOU decide.

Either of
unsigned'(ls_test'high downto ls_test'low +1 => '0')
-- treat ambiguous type as unsigned
or
unsigned(ls_test'high downto ls_test'low +1 => '0')
-- convert from (presumably SLV) to unsigned
should do what you want.

If it's too ugly or you are doing it more than once, wrap it in a function.
If you need it in different places, that's what packages are for.


(*) This may sound pedantic and a bit harsh.
And for
function "=" (a:unsigned,b:string) return boolean is ...
function "=" (a:unsigned,b:unsigned) return boolean is ...
most languages may actually give you the expected results, at least, as long as
you take care that the arguments are the same length.

But consider for a moment
function "<" (a:unsigned,b:[some type, maybe string]) return boolean is ...
Have ever been plagued by a list sorted as
1,10,11,12,13,2,3,4,5,6,7,8,9 ?

I know I have.

And I know which approach I prefer.

- Brian
 
ALuPin@web.de schrieb:

if ls_test(7 downto 1) = "0000000" then
With IEEE.numeric_std.all you can write

if ls_test(7 downto 1) = 0 then

because ls_test is defined as unsigned vector.

Unsigned can be compared to integer and so you do this independently
from the range.

Ralf
 
On Mar 30, 5:50 am, Bert_Paris <do_not_s...@me.com> wrote:
Then :

constant gWidth : positive :=8;
signal ls_test : signed(gWidth-1 downto 0) := (0=>'0', others=>'1');
Begin
process (ls_test)
begin
     if ls_test (ls_test'high downto ls_test'low +1) = -1 then
       report "all ones, LSB ignored !";
    end if;
end process;- Hide quoted text -

- Show quoted text -
There are also easier ways to strip off the lsb of an unsigned/signed
vector.

constant gWidth : positive := 8;
signal ls_test : unsigned(gWidth-1 downto 0);
....
if lstest / 2 = 0 then...

or:

if signed(lstest) / 2 = -1 then...

Andy
 
On Mar 30, 11:50 am, "ALu...@web.de" <ALu...@web.de> wrote:
Hi,

I am trying to do the following:

signal ls_test : unsigned(7 downto 0);

process(ls_test)
begin
     if ls_test(7 downto 1) = "0000000" then
       ...
    end if;
end process;

Now I want to have something like:

signal ls_test : unsigned(gWidth-1 downto 0);

process(ls_test)
begin
     if ls_test = (ls_test'high downto ls_test'low +1 => '0') then
       ...
    end if;
end process;

When compiling I get the following error:
"Operator "=" is not defined for such operands.

Can somebody share some light on it ?

Thank you.
Rgds, ALuPin
You can try something like this:

signal ls_test : unsigned(gWidth-1 downto 0);

process(ls_test)
begin
if ls_test = conv_std_logic_vector(0,gWidth) then
...
end if;
end process;

You can replace 0 with any unsigned integer constant.

Florin
 
On Mar 30, 11:47 am, Andy <jonesa...@comcast.net> wrote:
if signed(lstest) / 2 = -1 then...

Andy
oops, that won't work!

how about:

if (not (lstest / 2)) = 0 then...

Andy
 

Welcome to EDABoard.com

Sponsor

Back
Top