0
PROCESS(X,Y)
BEGIN
 OUT<=X;
 OUT<=OUT or Y;
END PROCESS;

I'm new to VHDL and I was testing out ways to assign logic values. Would this statement be a possible way to OR two values?

scary_jeff
  • 4,314
  • 13
  • 27
  • Where/how is `OUT` declared? – rtx13 Apr 14 '20 at 05:43
  • No. Signal updates occur in a different part of a simulation cycle than the resumption and subsequent suspension of processes. A combinational loop (a feedback path) without inversion will simply latch (with inversion it can oscillate). –  Apr 14 '20 at 06:30

1 Answers1

1

Note: OUT is a reserved keyword in VHDL. I assume you mean to reference a signal, so I've changed its name to OUTSIGNAL.

I have copied the process block from the Question with the signal name updated:

PROCESS(X,Y)
BEGIN
 OUTSIGNAL<=X;
 OUTSIGNAL<=OUTSIGNAL or Y;
END PROCESS;

As written, the process would not work as intended. VHDL signal assignments don't take effect until process execution reaches the end of the process block (or a 'wait' statement). Later signal assignments effectively override any prior signal assignments to the same signal, so the OUTSIGNAL<=X; statement is ignored in favour of the subsequent OUTSIGNAL<=OUTSIGNAL or Y; statement. The resulting behaviour of the process as written, depending on the initial value of OUTSIGNAL, is likely to be a set-only latch with Y as the set input.

In order to implement an OR gate, you could modify your process as follows:

PROCESS(X,Y)
BEGIN
 OUTSIGNAL<=X or Y;
END PROCESS;

... but this sequential process reduces to one statement, so you can just write it as a concurrent statement and eliminate the process entirely:

OUTSIGNAL<=X or Y;

If you'd like to retain the process, you could use a variable as follows:

PROCESS(X,Y)
 VARIABLE temp : STD_LOGIC;
BEGIN
 TEMP:=X;
 TEMP:=TEMP OR Y;
 OUTSIGNAL<=TEMP;
END PROCESS;

Variables in a VHDL process can be referenced and (re)assigned in successive process statements in the way that variables are referenced and (re)assigned in most imperative software languages.

rtx13
  • 2,580
  • 1
  • 6
  • 22
  • Your second process shown has a feedback loop in the second assignment to TEMP. Once a '1' it would stay a '1'. –  Apr 14 '20 at 06:34
  • 2
    @user1155120 I don't think so. `TEMP` is assigned a new value in the first line of the process. – Matthew Taylor Apr 14 '20 at 08:03
  • @rtx13 I think you are missing an important point in your answer, a point I'm sure you're aware of, but which needs explaining: that point is why `OUT<=X;` immediately followed by `OUT<=OUT or Y;` is no good. In other words, I think you need to mention this key difference between a signal and a variable. – Matthew Taylor Apr 14 '20 at 08:05
  • 1
    Please check [this](https://stackoverflow.com/questions/15485749/vhdl-variable-vs-signal/15499109) for the difference about `signals` and `variables`. – Kampi Apr 14 '20 at 09:45
  • 1
    @MatthewTaylor that's funny I was certain I wrote an explanation. Then again it was in the middle of the night and I was half asleep. I'll add some additional explanation. – rtx13 Apr 14 '20 at 17:47