I try to write programm on vhdl in ise 14.4 for crc16 calculation but dont understand why get "parse error, unexpected FOR" in it. Tried to put it into process but it dont works too.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity crc16 is port(
clk : in STD_LOGIC:='0');
end crc16;
architecture Behavioral of crc16 is
signal data:std_logic_vector(15 downto 0):="1010101010101010";
signal ext_data:std_logic_vector(31 downto 0);
signal crc16_original:std_logic_vector(15 downto 0):="1100000000000010";
signal crc16:std_logic_vector(15 downto 0);
signal position:std_logic_vector(5 downto 0);
signal crc_out:std_logic_vector(14 downto 0);
signal i:std_logic_vector(5 downto 0);
begin
for i in 1 to 15 loop
ext_data(i+16)<=data(i);
end loop;
for i in 1 to 15 loop
ext_data(i)<='0';
end loop;
while ext_data > "111111111111111" loop
for i in 0 to 31 loop
if ext_data(i)="1" position=i;
end loop;
crc16<= crc16_original srl 31-position;
ext_data<=ext_data xor crc16;
end loop;
for i in 0 to 14 loop
crc_out(i)<=ext_data(i);
end loop;
end Behavioral;
There are several issues to point out:
The for-loop must be in a process, so that is likely to cause the “parse error, unexpected FOR” that you see.
The relation compare with
>
may give unexpected result forstd_logic_vector
, so you may take a look at thenumeric_std
package for casting as for exampleunsigned(std_logic_vector)
before comparison is made.Compare
ext_data(i) = "1"
is illegal, since"1"
is taken asstd_logic_vector
, where asext_data(i)
isstd_logic
; insteadext_data(i) = '1'
will compile.Illegal construction around
if ext_data(i) = "1" position=i;
, since nothen
etc.There is an signal with identifier i, which i is also used as loop variable, with the result that
position <= i
is taken as aninteger
assign tostd_logic_vector
; use different names for signals and loop variables.Assign to signal is not
position = i
butposition <= i
, like elsewhere.Expression
31-position
mixesinteger
andstd_logic_vector
, which can't be done with the selected packages. Use casting withunsigned
.The
ext_data<=ext_data xor crc16
uses different size arguments, sinceext_data
is 32 bits andcrc16
is 16 bits; this does probably not yield the expected result.srl is not defined for
std_logic_vector
(VHDL-2002), so consider casting withunsigned
for well-defined behavior.Assuming that that your code is "sandbox" code, since it has no outputs.
Based on the above, you may consider doing some initial experiments with smaller designs, in order to get familiar with the different VHDL constructions, and learn how this simulates and maps to hardware; remember VHDL is a "Hardware Description Language" and not a programming language.
Below is some code that compiles in ModelSim, but is unlikely to give the expected result: