Using Xilinx, I need to compare a 'variable' called 'row', defined as:
variable row : std_logic_vector(2 * n - 1 downto 0);
This line was given to me, now I need an if statement that will execute if row is = 1.
I have tried:
if (row = "1") then
but the IDE warns me that this condition will always result in false? which should not happen.
If I try if (row = '1') then
or if (row = 1) then
then I get the error:
found '0' definitions of operator "="
Googling this, the only suggestion is to include libraries that I have already included:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
1 Answer 1
Your variable is a std_logic_vector and you compare it to an integer. You have to cast the std_logic_vector like this:
if(to_integer(signed(row)) = 1)
or if(to_integer(unsigned(row)) = 1)
-
3\$\begingroup\$ "1" isn't an integer, it's a std_logic_vector of length 1. \$\endgroup\$DonFusili– DonFusili2019年12月03日 15:07:25 +00:00Commented Dec 3, 2019 at 15:07
-
1\$\begingroup\$ For completeness, 1 is an integer and '1' is a bit or character. \$\endgroup\$Kevin Kruse– Kevin Kruse2019年12月03日 15:28:40 +00:00Commented Dec 3, 2019 at 15:28
-
2\$\begingroup\$ @Kevin We would like to call it 'bit' because 'character' is a convention in C or C++ which represents a byte. \$\endgroup\$Mitu Raj– Mitu Raj2019年12月03日 15:35:59 +00:00Commented Dec 3, 2019 at 15:35
-
\$\begingroup\$ @MituRaj "character" is well-defined in VHDL and is valid here. The literal '1' is not necessarily a bit nor a character, it may be either depending on what the literal is compared with or assigned to. \$\endgroup\$Kevin Kruse– Kevin Kruse2019年12月03日 16:02:54 +00:00Commented Dec 3, 2019 at 16:02
-
2\$\begingroup\$ That was just a convention introduced in VHDL for people from software field. We hardware engineers rarely use it in HDL. It makes more sense to assign a bit vector = 01000001 rather than assigning it as a char by 'A' \$\endgroup\$Mitu Raj– Mitu Raj2019年12月03日 16:11:08 +00:00Commented Dec 3, 2019 at 16:11
(others => 'U')
(might depend on simulator), which is not equal to "1". But you might think you initialize it, or you wouldn't ask this question. So supply us with a minimal failing example. \$\endgroup\$