Professional Documents
Culture Documents
Thomas Lenzi
Objective
2
State Machines
State Machines
• A state machine is a construction in which a system
is described by states in which it can be.
Otherwise Otherwise
Always
State 4 State 3
5
Exercise
6
Solution
Less than 2€
Exactly 2€
Nothing happens
Inserted 1€ More than 2€
Gave 1€
Waiting for money Give fruit
Gave 0.50€
Inserted 0.50€ More than 2€
Less than 2€
More than 2€
Always
Give money back
7
Processes
Processes
• In order to code sequential statements in
VHDL, you need to use processes.
9
Variables & Signals I
• When using processes, you can create
variables at the beginning of the
process.
10
Variables & Signals II
• In this example, the process will fire
every time the clock changes, but the
IF statement requires it to be high.
11
Variables & Signals III
12
Propagation delays and
variables
• You must use variables with care as they will
produce cascading logic.
13
Sequential Statements
If / elsif / else
• When encoding
conditions, be sure to
cover all possible cases!
15
Case
• The case statement has a
similar use as in C.
16
For & While
17
Using the Clock
• To use the clock as timer, you have to
make use of the rising_edge function.
It will ensure that the process is fired
when the clock changes from low to
high.
18
Exercise
19
Solution
20
Packages
Packages
• Next to regular VHDL entities, you can also create
Packages.
22
Package Structure
• Packages are decomposed in two
parts: header and body.
23
Types and Constants
• In VHDL, you can create new types:
24
Functions
25
Procedures
26
Using Packages
• To use your package
you need to include if
using the use statement.
• Functions and
procedures can then be
called.
27
Back to State
Machines
A Better State Machine
29
Solution
State transitions State actions
30
Simulations
Test Benches
• Test Benches are VHDL entities that drive signals
into a Unit Under Test (UUT).
32
Create a Test Bench
• Go to “Project > New Source…”
• Select “VHDL Test Bench” and give it a name with a .vhd extension, then click
“Next”
• On the next window, select the file for which you want to create a test bench
and click “Next” and then “Finish”
33
ISE Simulation Environment
• To use the test bench, you need to
switch to the simulation environment
by selecting the Simulation view.
35
Code to Analyse
36
Generating Signals
• To analyse our logic, we will use the following
code:
37
Running the Simulation
38
Simulation Result
39
Exercise
40
Best Practice VHDL
Common
• The file’s name is the entity’s name
43
Vectors
44
Clocks and Resets
• Use synchronous resets
45
Communication
Protocols
UART
• The Universal Asynchronous Receiver/Transmitter (UART)
is a protocol that uses two wires: one to receive and one to
transmit data.
47
I2C
• In I2C, a master controls multiple slave by addressing them.
• The master and slaves use the same data line (sda) to
transmit information that is synchronised to a clock line (sck).
48
SPI
• SPI uses a Chip Select SS# bus
to allow the master to select the
slave it wishes to address.
49
Exercise
Using the 7-segments
display
Exercise
53
Step 1: IOs
• clk_50MHz_i : input clock
54
Step 2: Clock
• Using a counter, we
generate a 1 kHz “clock”.
55
Step 3: States
56
Step 4 : Data Translation
• The 7-segments
display uses a data
bus of 7 bits while
the user uses 4 bits
representing a
number.
• We have to convert
the number to the
display.
57
Step 5 : Data Signalling
58