Lecture 3 Handout
Lecture 3 Handout
Instructors:
Daniel Holanda Noronha, [email protected]
Cristian Grecu, [email protected]
1
19-07-24
2
19-07-24
○ '0': logic 0
○ '1': logic 1
○ 'Z': High Impedance
■ The symbol Z indicates that a node is being driven neither HIGH nor
LOW.
■ The node is said to be floating, high impedance, or high Z.
■ Common ways to produce a floating node
● forget to connect a voltage to a circuit input
● Assume that an unconnected input is the same as an input with
the value of 0.
■ This mistake may cause the circuit to behave erratically as the
floating input randomly changes from 0 to 1.
■ Logic gates with possible outputs 0,1, and Z do exist and CAD tools
can synthesize such circuits
5
3
19-07-24
4
19-07-24
But we are going to take this MUCH further and describe circuits
at a much higher level.
● Process syntax
...
process (sensitivity_list)
begin
statements
end process;
...
10
5
19-07-24
...
● The sensitivity list process (sensitivity_list)
begin
○ Is a list of signals statements
○ A change in value on one or more of these end process;
...
signals, causes the process to be activated
○ Example:
process(clk)
defines the start of a process that is
"executed" whenever CLK changes
11
entity MY_ENTITY is
port(clk: in STD_LOGIC;
d: in STD_LOGIC_VECTOR(3 downto 0);
rising_edge(clk)
q: out STD_LOGIC_VECTOR(3 downto 0)); is the same as
end MY_ENTITY; clk'event and clk = '1'
architecture MY_ARCH of MY_ENTITY is
begin
process(clk) begin
if rising_edge(clk) then
q <= d;
end if;
end process;
end MY_ARCH; 17
6
19-07-24
● Moore machine
○ Output depends only on the current state of the machine only
● Mealy machine
○ Output depends on both the current state and input(s).
18
Both of these images show a Moore state machine, since the output only depends on current state
Moore Mealy
7
19-07-24
● Moore machine:
...
architecture MY_ARCH of MY_ENTITY is
begin
process (clk)
variable PRESENT_STATE : bit_vector(1 downto 0) := "00";
begin
if (clk’event and clk = '1') then
case PRESENT_STATE is
when "00" => PRESENT_STATE := "01";
when "01" => PRESENT_STATE := "10";
when "10" => PRESENT_STATE := "11";
when "11" => PRESENT_STATE := "00";
end case;
Z <= PRESENT_STATE; -- update output Z
end if;
end process;
end MY_ARCH; 25
● Moore machine:
architecture MY_ARCH of MY_ENTITY is
begin
process (clk)
type state_set is (StateInit, StateWait, StateSample, StateDisplay);
variable PRESENT_STATE : state_set;
begin
if (clk’event and clk = '1') then
● To make code more readable, you can
define enumerated types
case PRESENT_STATE is
when StateInit => PRESENT_STATE := StateWait;
● Here, we have defined a variable
when StateWait => PRESENT_STATE := StateSample; called CURRENT_STATE that
when StateSample => PRESENT_STATE := StateDisplay; can take on one of four values:
when StateDisplay => PRESENT_STATE := StateInit; StateLive, StateWait, StateSimple,
end case; StateDisplay.
Z <= PRESENT_STATE; -- update output Z
end if;
end process; After synthesis, there will be two bits for each signal
end MY_ARCH; 26
8
19-07-24
27
28
9
19-07-24
● Operation is as follows:
○ If Reset is 1, the value in the register is set to 0, regardless of clock
(asynchronously)
○ Otherwise, on each rising edge of the clock
■ if load is 1, load in value from D into register
■ otherwise, rotate value in register one bit to the right
29
30
10
19-07-24
library ieee;
use ieee.std_logic_1164.all; Any concurrent statements not inside a
process are also considered processes
entity MY_ENTITY is
port (A, B,C,D : in STD_LOGIC;
X,Y,Z : out STD_LOGIC);
end MY_ENTITY;
architecture MY_ARCH of MY_ENTITY is
begin
X <= A and B and C;
Y <= C and not D; These statements are treated as three processes
Z <= A xor B xor D;
end MY_ARCH;
The "sensitivity list" is made of all signals of
the assignment
In this case: A, B and D
31
32
11
19-07-24
● Signals:
○ Used to transmit data between processes
● Variables:
○ Used within a process to help describe behaviour
Note: There are things called “shared variables” but don’t use them.
33
● Note:
○ All inputs and outputs of a Process are signals.
34
12
19-07-24
35
13
19-07-24
● What we learned:
○ Don’t use a signal to
communicate within a process
37
38
14
19-07-24
39
40
15
19-07-24
● Wait until
○ The wait until form suspends a process until a change occurs on one or
more of the signals in the statement and the condition is evaluated to be
true.
process
process(A) begin
begin wait until A'event;
-- sequential -- sequential
statements statements
end process; end process;
41
…
EN_1 <= '0';
EN_2 <= '1';
wait for 10 ns;
EN_1 <= '1';
EN_2 <= '0';
wait for 10 ns;
EN_1 <= '0';
wait for 10 ns;
wait; -- end of test
...
42
16
19-07-24
43
44
17
19-07-24
45
46
18
19-07-24
47
● If you learn VHDL from a book, write your code using the constructs they
describe, and try to compile it to a hardware (FPGA, ASIC), it probably won’t
work!
○ I’ll tell you in this slide set, and also talk about how to make sure it
does work
48
19
19-07-24
50
20
19-07-24
● In the next few slides, I am going to show you the types of VHDL code that
synthesizable by all tools.
○ If you restrict your VHDL to those types of code, your code will be
synthesizable by all tools
51
● To make sure your VHDL is synthesizable, every process must be one of three
types:
process (SEL, A, B)
begin
if (SEL = ‘0’) then
Y <= A;
else
Y <= B;
end if;
end process;
52
21
19-07-24
● To make sure your VHDL is synthesizable, every process must be one of three
types:
53
process (A, B)
begin
if (SEL = ‘0’) then
Y <= A; Rule 1: Every input (that can affect the
else outputs) must be in the sensitivity list.
Y <= B;
end if;
end process; Rule 2: Every output must be assigned
a value for every possible combination
of the inputs.
54
22
19-07-24
process (SEL,A, B)
begin
if (SEL = ‘0’) then Rule 1: Every input (that can affect the
Y <= A; outputs) must be in the sensitivity list.
end if;
end process;
Rule 2: Every output must be assigned
a value for every possible combination
of the inputs.
56
● To make sure your VHDL is synthesizable, every process must be one of three
types:
58
23
19-07-24
● To make sure your VHDL is synthesizable, every process must be one of three
types:
59
● If you want to synthesize your circuit, every process must fall exactly into one of
these categories.
● What if I have a big process that will not fit in any of the three types?
○ You need to break it up into blocks, where each block does fit into one of
these types.
60
24
19-07-24
● Summary
○ Make sure every process is one of these three types:
■ Type 1: Purely Combinational
■ Type 2: Purely Synchronous
■ Type 3: Purely Synchronous with async set/reset
62
25
19-07-24
63
26