Ncvhdl Problem with simple logical operators

M

Martin

Guest
Hi,

I have a very simple operator problem in VHDL. I try to compare some
inputs with logical operators but get an error message...

entity test is
port (
paddr : in std_logic_vector(15 downto 0);
psel : in std_logic;
penable : in std_logic;
pwrite : in std_logic
);
end entity test;

signal wrfifo_full : std_logic;

process (paddr, psel, penable, pwrite, wrfifo_full) is
begin
if (((paddr(8 downto 2) = "1000000")) and (psel and penable) and
(pwrite and not(wrfifo_full))) then
dt_fifo_wr_i <= '1';
else
dt_fifo_wr_i <= '0';
end if;
end process;

Unfortuantely, I get then the following error message:

if (((paddr(8 downto 2) = "1000000")) and (psel and penable) and
(pwrite and not(wrfifo_full))) then | ncvhdl_p:

|
*E,OPTYMM (hdl/vhdl/test.vhd,523|43): operator argument type mismatch
87[4.3.3.2] 93[4.3.2.2] [7.2]

Anyway sees what is the problem?

Cheers
 
Martin <sportfreund@gmx.at> writes:

Unfortuantely, I get then the following error message:

if (((paddr(8 downto 2) = "1000000")) and (psel and penable) and
(pwrite and not(wrfifo_full))) then | ncvhdl_p:
(psel and penable) returns std_logic
(pwrite and not(wrfifo_full)) returns std_logic

You need to do

if ((paddr(8 downto 2) = "1000000") and
((psel and penable) = '1') and
((pwrite and not(wrfifo_full)) = '1')) then

//Petter

--
..sig removed by request.
 
On Tue, 26 Oct 2010 03:14:34 -0700 (PDT), Martin <sportfreund@gmx.at> wrote:

Hi,

I have a very simple operator problem in VHDL. I try to compare some
inputs with logical operators but get an error message...

entity test is
port (
paddr : in std_logic_vector(15 downto 0);
psel : in std_logic;
penable : in std_logic;
pwrite : in std_logic
);
end entity test;

signal wrfifo_full : std_logic;

process (paddr, psel, penable, pwrite, wrfifo_full) is
begin
if (((paddr(8 downto 2) = "1000000")) and (psel and penable) and
(pwrite and not(wrfifo_full))) then
dt_fifo_wr_i <= '1';
else
dt_fifo_wr_i <= '0';
end if;
end process;

Unfortuantely, I get then the following error message:

if (((paddr(8 downto 2) = "1000000")) and (psel and penable) and
(pwrite and not(wrfifo_full))) then | ncvhdl_p:

|
*E,OPTYMM (hdl/vhdl/test.vhd,523|43): operator argument type mismatch
87[4.3.3.2] 93[4.3.2.2] [7.2]

Anyway sees what is the problem?
"and" operates on booleans to provide a boolean result.
or
"and" operates on std_logic to provide a std_logic result.
but
"if" requires a boolean expression...

You have written
if <bool expression> and <std_logic expression> then...

The least effort solution is to write
if <bool expression> and (<std_logic expression> = '1') then...
and this may be the best solution here.

But if there are a lot of these in your code, it suggests you are fighting the
type system rather than using it.

Strong typing is your friend... if you can learn to get along.

One trick for learning to get along: The type system allows overloading by
function result, so you can overload "and" with your own function, e.g. taking
two std_logic arguments and returning a boolean. I don't see any way of creating
ambiguities or dangers doing this.

A package of functions like these can perhaps simplify and clarify your code.

- Brian
 
  if ((paddr(8 downto 2) = "1000000") and
      ((psel and penable) = '1') and
      ((pwrite and not(wrfifo_full)) = '1')) then
Thanks a lot, that does the trick!
 
For this to be useful, you would have to also overload AND for
combinations of sl and bool (on both sides too) to return bool.

Then you would have a problem with "if abool and (asl and bsl) then"
because the return type of the second "and" (inside the paretheses) is
ambiguous (because the first "and" could accept either bool,bool or
bool,sl operands).

I wrote and use functions is1() and is0() to convert sl to boolean,
while handling weak values and warning on other metavalues (while
returning false).

Andy
 
On Tue, 26 Oct 2010 08:23:12 -0700 (PDT), Andy <jonesandy@comcast.net> wrote:

For this to be useful, you would have to also overload AND for
combinations of sl and bool (on both sides too) to return bool.
It's still somewhat useful without those combinations - and avoids the ambiguity
problems you note.

I wrote and use functions is1() and is0() to convert sl to boolean,
while handling weak values and warning on other metavalues (while
returning false).
Another way of skinning the cat...

- Brian
 
On Oct 26, 6:53 pm, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
On Tue, 26 Oct 2010 08:23:12 -0700 (PDT), Andy <jonesa...@comcast.net> wrote:

For this to be useful, you would have to also overload AND for
combinations of sl and bool (on both sides too) to return bool.

It's still somewhat useful without those combinations - and avoids the ambiguity
problems you note.
Without those combinations, here are a few exampes of what would work
and what would not:

if asl and bsl then -- would work
if (asl and bsl) and abool then -- would work
if asl and abool then -- would NOT work

The resulting confusion would be worse than that of the original
situation.

Andy
 

Welcome to EDABoard.com

Sponsor

Back
Top