Recall that concurrent signal assignment statements all operate in parallel. The VHDL process statement is effectively a block around a bunch of logic and control. Inside of a process statement, statements are executed sequentially which allows us to introduce sequencing and control. Inside of a process statement, we can use additional VHDL syntax like if-thenelse and case statements. Each VHDL process statement operates in parallel with other processes and in parallel with other concurrent VHDL statements. Note: Operations with sequencing (like Case and If-Then-Else) must, and can only, be used inside of a process.
Page 1
library ieee; use ieee.std_logic_1164.all; entity multiplexer_2to1 is port (x0,x1 : in std_logic; s : in std_logic; f : out std_logic ); end multiplexer_2to1;
architecture prototype of multiplexer_2to1 is begin process (x0,x1,s) -- process has a sensitivity list. begin if (s = '0') then -- can use if-then-else inside of a process f <= x0; else f <= x1; end if; end process; end prototype;
Page 2
Comments
Signals changed inside of the process are not changed until the process has completed evaluating every statement inside of the beginend. There is no delay associated with the process itself; i.e., a process is a programming construct and is assumed to execute in 0 time. Of course, the statements inside of the process can have delays associated with them.
Page 4
architecture prototype of multiplexer_4to1 is begin process (x0,x1,x2,x3,s) begin if (s = "00") then f <= x0; elsif (s = "01") then -- notice the syntax elsif without spaces f <= x1; elsif (s = "10") then f <= x2; else f <= x3; end if; end process; end prototype;
Page 5
segment 3
segment 2
segment 4 segment 6
segment 1
segment 5
segment 0
Page 6
Page 7
Note: Our case statement has a default for situations where no condition matches (we use the others keyword).
In the default assignment we can use the null keyword which is much like saying doesnt matter, so do nothing/whatever.
Page 8
Page 9
Comments
In addition to statements like case statements and if-then-else statements, the concurrent signal assignment (i.e., lhs <= rhs ;) works inside a process (we used it!). However, other concurrent assignment statements do not work! We cannot use a selected or conditional signal assignment statement inside of a VHDL process.
Page 10
Page 11
library ieee; use ieee.std_logic_1164.all; entity dlatch is port (d, g : in q, qbar end dff;
architecture prototype of dlatch is begin process (d,g) begin if (g=1) then q <= d; qbar <= not d; end if; end process; end prototype;
Page 12
Signal attributes
Definition: When the value of a signal has changed (i.e., a signal transition), we say that an event has occurred on the signal. Definition: Signals have properties that we can pay attention to these properties are called attributes. An event is a type of attribute. The syntax for observing an attribute on a signal is: signal_nameattribute_name -- notice tick mark between the -- signal_name and the -- attribute_name
Page 13
Detection of the falling edge (assuming a signal called temp): (tempevent and temp = 0)
Page 14
library ieee; use ieee.std_logic_1164.all; entity dff is port (d, clk : in std_logic; q : out std_logic); end dff; architecture prototype of dff is begin process (clk) begin if (clkevent and clk=1) then q <= d; end if; end process; end prototype;
Page 15
Page 16
Page 17
Page 18
architecture prototype of dffsr is begin process (clk,s,r) begin if (s = 1) then q <= 1; elsif (r = 1) then q <= 0; elsif (clkevent and clk=1) then q <= d; end if; end process; end prototype;
-- active high (precedence over reset). -- active high -- positive edge triggered.
Page 19
Page 20
Page 21
Comments
There are other types of signal attributes in addition to the event attribute. We dont need them, so we wont talk about them.
You can add other types of control signals in addition to the set and reset in a similar fashion to what we have seen. You can make the set and reset signals synchronous by changing the structure of the if-then statement inside the process. You can make other types of flip-flops (e.g., TFF) using code very similar to what we have seen.
Page 22
Page 23
VHDL types
We need to introduce a new type to represent the states of our state machine. The syntax to declare a new type is: type type_name is ( value_1, value_2, , value_n ) ; We also declared two signals in the declarative section of the architecture (as we normally might do), but have restricted their values to our new type.
Page 24
Example (1)
To illustrate Moore Machines in VHDL, we need a problem. Consider the following verbal description of a circuit: A circuit has one input X and one output Z. A 1 is asserted at its output Z when it recognizes the following input bit sequence 1011. The circuit does not reset once the pattern is found, but continues to recognize the string. E.g., if the input is ..1011011, then the output will be high twice: Z=..0001001.
We can proceed to draw a state diagram for a Moore Machine, and develop the VHDL from the state diagram.
Page 25
Example (2)
The state diagram for our verbal description is:
0
S0/0
1 1
S1/0 ..1
0 0
S2/0 ..10
1 1
..1011
1
..101
S3/0
S4/1
Page 26
Example (3)
We see that we have input X, output Z and Moore States 0 through 4.
Page 27
Example (4)
First process: computes the next state of the system (the following VHDL process statement would be placed in the architecture body):
(curr_state, x) -- continued from previous box when moore_s3 => if (x = '1') then next_state <= moore_s4; else next_state <= moore_s2; end if; when moore_s4 => if (x = '1') then next_state <= moore_s1; else next_state <= moore_s2; end if; end case; end process;
curr_state is moore_s0 => (x = '1') then next_state <= moore_s1; else next_state <= moore_s0; end if; when moore_s1 => if (x = '1') then next_state <= moore_s1; else next_state <= moore_s2; end if; when moore_s2 => if (x = '1') then next_state <= moore_s3; else next_state <= moore_s0; end if; -- continued in next box
Page 28
Example (5)
We see that the next state process has in its sensitivity list the current state and the input signal. These are the two things that are required to determine the next state. Based on the current state and the current input value, we can determine the next state value
Page 29
Example (6)
Second process (the following VHDL process statement would be placed in the architecture body): Update current state with the next state at the rising edge of the clock; If we have a reset, we need to return to our initial state.
process (clk, reset) begin if (reset = '1') then curr_state <= moore_s0; elsif (clk = 1 and clkevent) then curr_state <= next_state; end if; end process;
Note that the sensitivity list of this process includes the clock and reset signals which are those signals that can change the outputs that are possibly changed by the process.
Page 30
Example (7)
Our circuit also has output Z, which should also be included.
We can include a concurrent signal assignment statement (in addition to the two processes previously described) in the architecture body of the VHDL Description:
-- simple concurrent signal assignment to determine outputs. -- placed in the architecture body along with the two process statements. z <= '1' when (curr_state = moore_s4) else '0';
Page 31
Simulation
Page 32
outputs
next state
curr state
inputs
clock
reset
Page 33