Reputation: 21
This error has been mindfucking me for long, I don't know what to do. I get the same error in other codes, but this one is a simple one, so maybe it's easier to find out what's the problem.
It's a frequency selector, if the switch (clau) is on, the frequency changes.
library IEEE;
use IEEE.numeric_bit.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity selector_frequencia is
Port ( unHz : in bit ;
centHz : in bit ;
Clock : out bit;
clau: in bit);
end selector_frequencia;
architecture Behavioral of selector_frequencia is
begin
if (clau = "0") then Clock <= unHz;
else Clock <= centHz;
end if;
end Behavioral;
And the error I get is this one:
ERROR:HDLParsers:164 - "C:/Documents and Settings/Administrador/Escritorio/practica_digital/practica_digital/selector_frequencia.vhdl" Line 23. parse error, unexpected IF
Thank you.
Upvotes: 2
Views: 2093
Reputation: 7838
I'm not really an expert in VHDL but I believe you should use the if
statement inside a process:
architecture Behavioral of selector_frequencia is
begin
fqsel:PROCESS(unHz , centHz , Clock , clau)
BEGIN
if (clau = '0') then
Clock <= unHz;
else
Clock <= centHz;
end if;
END PROCESS fqsel;
end Behavioral;
Upvotes: 3
Reputation: 3365
As Alex pointed out, your if statement needs to be inside a process block. In addition, VHDL is not C...you are not supposed to put parens () around the conditional or it looks like a procedure/function call or a signal range ie: my_bus(7 downto 0) but it's a syntax error because if is a reserved word. Try:
process (clau, unHz, centHz)
begin
if clau = '0' then
Clock <= unHz;
else
Clock <= centHz;
end if;
end process;
Finally, outside of a process, you can just use a conditional signal assignment, which is a short-hand way of implementing the equivalent process and if statements:
Clock <= unHz when clau='0' else centHz;
Upvotes: 1
Reputation: 2728
You are using an assignment statement in your IF clause:
// This is assignment, you are assigning 'clau' to 0 and then checking it in 'if'
if (clau = "0") then Clock <= unHz;
// Try this, note the double '='
if (clau == "0") then Clock <= unHz;
Assignment statements should be within a PROCESS block.
Hope this helps.
Upvotes: 0