Forum Discussion

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

Advices on VHDL signals initialization (Quartus synthesis vs Modelsim simulation)

Hi everybody,

I use Modelsim to simulate my VHDL design, and when declaring signals I usually don't add any initialization since I know that inside the FPGA the logic is "automatically" initialized after the device exits from POR.

Unfortunately this is becoming an issue with Modelsim since to "safely" run the simulation all the signals should be initialized, generally to '0' or (others => '0'). Up to now I've worked by adding initializations to all signals when using the file in Modelsim, and commenting them away when using them in my Quartus project:

signal a : std_logic; --Quartus

signal a : std_logic := '0'; --Modelsim

Now I'm wondering: from the Quartus synthesis point of view is it advisable to initialize ALL the signals when declaring them in my VHDL? Will Quartus treat all the signals initialized to '0' in the same way as the uninitialized ones?

This way I could avoid adding/working with the 2 versions of each files (with and without signals initialization).

Any suggestion?

Thank you very much for your help :)

Claudio

10 Replies

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

    Quartus can use the initilised values no problem - it gives the registers their power up value. It will also initialise registers from their async reset value. Unitialised signals can be set to either '0' or '1' at power up.

    I would never work with two versions of the same file.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Tools have their own mind and history. In the past, any initialisation in vhdl code was ignored. Now I hear it is seen as you want it so.

    For initial values, additionally there is tool setting (power up don't care ON or OFF) lets you do that and may be this or vhdl overrides, not sure.

    initial values in modelsim can be left as undefined until they get driven, this shouldn't harm except in some cases e.g. accumulator stays undefined as it lives with initial undefined value.

    In any case of having different code when targetting synthesis and sim you can easily set translate switch in same file
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you all for the answers. At the moment I will keep all the initializations, then I will check if some unwanted overhead logic is added after Quartus compilation.

    Kaz, what do you mean with "you can easily set translate switch in same file"? Could you please make an example? Thanks!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The translate_off and translate_on synthesis directives indicate whether the Quartus II software or a third-party synthesis tool should compile a portion of HDL code that is not relevant for synthesis. The translate_off directive marks the beginning of code that the synthesis tool should ignore; the translate_on directive indicates that synthesis should resume. You can also use the synthesis_on and

    synthesis_off directives as a synonym for translate on and off

    e.g. (try this, not tested)

    signal x : integer translate_off := 10 translate_on;

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

    translate_off/on doesnt quite work like that. They are plaed inside comments embedded within the code, like this:

    
    --synthesis translate_off
    signal a : integer; -- synthesisor will not see signal a
    --synthesis translate_on
    

    you cannot embed translate_on/off in the middle of a line, you'll get a syntax error.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    these translate_on/off are mostly used to hide debug code from the synthesisor (often stuff that will be no way synthesisable, like fileIO).

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

    Tricky, being too lazt to test sorry, would it work like this:

    signal x : integer

    --translate_off

    := 10

    --translate on

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

    should do (but dont forget the synthesis bit).

    Bit of a faff though
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    At the moment I will keep all the initializations, then I will check if some unwanted overhead logic is added after Quartus compilation.

    --- Quote End ---

    It won't. All registers have a power-on default state of "zero", if you initialize a register signal to "one", an inverter will be placed after the register in the synthesized netlist ("not pushback").

    A problem arises, if you want both asnychronous set and reset for a register signal. Quartus needs to implement an additional latch and XOR logic to emulate the asynchronous set/reset. A warning will indicate this.