Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Initialize parameter of an array type

Hi,

In VHDL, we can have something like this:

TYPE memory1 is array (0 to 11) of std_logic_vector(7 downto 0);

constant RVSeq: memory1 := (X"40", X"52", X"56", X"30", X"30", X"34", X"30", X"30", X"35", X"30", X"31", X"2A");

in which we initialize each member of array RVSeq to a fixed value.

How do we do the same thing in Verilog? Example:

parameter [7:0] RVSeq [11:0] = (8'h40, 8'h52, 8'h56, 8'h30, 8'h30, 8'h34, 8'h30, 8'h30, 8'h35, 8'h30, 8'h31, 8'h2A);

It gives me compilation error of error (10170): verilog hdl syntax error at rs232.v(22) near text ","; expecting ")"

Thanks for the advice!

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Try this; it doesn't give me any errors.

    parameter bit [7:0] RVSeq [11:0] = '{8'h40, 8'h52, 8'h56, 8'h30, 8'h30, 8'h34, 8'h30, 8'h30, 8'h35, 8'h30, 8'h31, 8'h2A};

    Note that it's SystemVerilog syntax. You can change "bit" to "reg" or whatever type you want. Quartus just complains if no type is given.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Thanks for your reply. It does not work in Verilog. It gives me compilation error of:

    error (10170): verilog hdl syntax error at rs232.v(22) near text '
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I'm doing VHDL but on first sight it might be the "'" at "{" that is claimed.. Maybe worth removing this (the "'" between "8" and "h" to identify the number as hexadecimal is accepted I think).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    Thanks for your reply. It does not work in Verilog. It gives me compilation error of:

    error (10170): verilog hdl syntax error at rs232.v(22) near text '

    --- Quote End ---

    That was why I mentioned that it was SystemVerilog syntax. Quartus supports it, but it needs to be told that the file is SystemVerilog or else it will give errors because that syntax does not exist in regular Verilog. If you rename RS232.v to RS232.sv, Quartus will treat the file as SystemVerilog automatically.

    If you explicitly need Verilog and not SystemVerilog (for compatibility with Xilinx's ISE tool that does not allow SystemVerilog, for example), I don't have a solution. This kind of thing is why I prefer SystemVerilog whenever possible.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    I'm doing VHDL but on first sight it might be the "'" at "{" that is claimed.. Maybe worth removing this (the "'" between "8" and "h" to identify the number as hexadecimal is accepted I think).

    --- Quote End ---

    Hi, thanks for your reply. I think i would use back VHDL in this case to solve my problem. I believe in verilog we cannot do this kind of array initialization as easy as this. However, my application requires me to do so. Thanks again!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    That was why I mentioned that it was SystemVerilog syntax. Quartus supports it, but it needs to be told that the file is SystemVerilog or else it will give errors because that syntax does not exist in regular Verilog. If you rename RS232.v to RS232.sv, Quartus will treat the file as SystemVerilog automatically.

    If you explicitly need Verilog and not SystemVerilog (for compatibility with Xilinx's ISE tool that does not allow SystemVerilog, for example), I don't have a solution. This kind of thing is why I prefer SystemVerilog whenever possible.

    --- Quote End ---

    Hi, thanks for your reply. I would use VHDL in this case since i am more familiar with it. Thanks again!