Search code examples
vhdl

Where should a constant be declared?


I want to create an entity that has two constants. I would prefer the declaration to be in the entity declaration and not in the architecture, but I need to use the constants in the architecture.

  • If I define them in the entity declaration, will they be known in the architecture?
  • When I use the entity as a component, will I need to redefine the constants again, or could I write only the ports?
  • Any other differences that I should be aware of?

Solution

  • To answer your questions:

    1. Constants in the entity are available in the architecture.
    2. A component does not have (or need) constants.
    3. A constant in the entity applies to all architectures, not just one of them.

    But as Charles said in his answer, you may want to consider using generics instead of constants if they are actually "constants" that you want to sometimes change.