-1

Where the KEYWORDS variable and constant have to be used in VHDL coding, I'm aware of the scope of both of them, but unable to figure out which one has to be used when??

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3751971
  • 49
  • 1
  • 9

2 Answers2

0

Use Variable when you want to vary (modify) the quantity you are declaring, Constant when you don't. Or Signal if you want to vary it AND it's shared between different processes, ports or components.

But remember that Signal has different update semantics, avoiding the hazards and errors that can occur if you shared variables between processes in any language.

Community
  • 1
  • 1
0

Brian is correct. Only use variables for data that changes. Constants (as their name implies) is for data that does not change. In general I don't recommend that beginners to VHDL use variables, as they can synthesize differently than expected. I would recommend sticking to signals for holding your dynamic data.

Variables update immediately when they are assigned. Signals take one clock cycle if they are in a sequential process or update immediately if they are in a combinational piece of code

Read more about variables vs. signals in VHDL

Russell
  • 3,384
  • 4
  • 31
  • 45