Lecture 4 Handout
Lecture 4 Handout
1
19-07-25
● During the last lectures many of you came up with different combinational
circuits, but often they were all right (had the same behaviour)
○ If different circuits can have the same behaviour, which circuit is the best
one to implement?
■ Answer: The smallest one!
2
19-07-25
Don't worry this for now, just be aware that this exists
5
● Simple example
○ (P AND NOT A) OR (P AND A) = P AND (A AND NOT A) = P
0 0 0 0 0
0 1 1 0 1
1 0 0 0 0
1 1 0 1 1
3
19-07-25
● Karnaugh maps
○ A graphical method to do logic minimization
○ Works well for problems with up to four variables
4
19-07-25
10
5
19-07-25
Y = (A.C')+ B'
11
● Is this a part of the daily job of an engineer that works with digital design?
○ No! The tools do that for you now!
This means that if The tool will
you write the VHDL probably implement
for this something like this
● Does that mean that it doesn't really matter how I write VHDL?
○ No! The tool can do simple logic minimization, but we are responsible for
creating larger designs that are efficient (especially in RTL level)
12
6
19-07-25
13
14
7
19-07-25
● All Digital Designers must understand how math works inside of an FPGA
● The first step to that is understanding how signed and unsigned signal types
work
○ Signed and unsigned types exist in the numeric_std package
○ A signal that is defined as type signed means that the tools interpret this
signal to be either positive or negative
○ A signal that is defined as type unsigned means that the signal will be
only positive.
○ Internally, the FPGA will use Two's Complement representation.
15
● Example
○ A 3-bit signal can be interpreted according to the table below:
Note: To convert from negative to positive (and vice versa) invert all bits and add 1 16
8
19-07-25
● Unintuitive thing:
○ Whether or not the signals are defined as signed or unsigned does not
affect how some of the actual binary math is performed
● Unsigned example:
○ Lets calculate 4 (which is 100) + 2 (which is 010)
■ 100 + 010 = 110
● Converting back to decimal: 110 -> 6
○ Result is right!
● Signed value
○ Lets calculate -4 (which is 100) + 2 (which is 010)
■ 100 + 010 = 110
● Converting back to decimal: 110-> -2
○ Result is right!
17
18
9
19-07-25
19
20
10
19-07-25
21
● So now we know how to design with flip-flops and registers, and we know
how to specify such circuits in VHDL.
● Using the state machine design techniques, you can design any state machine
○ You already know how to describe any of them in behavioural VHDL.
● However, there are some very common sequential circuits that are used so
often, they are worth talking about separately.
○ Shift Registers
○ Counters
○ Linear-Feedback Shift Registers (LFSR’s)
22
11
19-07-25
23
29
12
19-07-25
INSIG
39
13
19-07-25
40
● There are many ways to do a counter and many different kinds of counters
● We can actually make a counter using a Moore state machine
41
14
19-07-25
15
19-07-25
52
53
16
19-07-25
● One-hot counter
○ Count:
It is a circular shift register!
100000000 > 01000000 > 00100000 > etc. (with some minor differences)
○ Advantage:
■ fast counting
○ Disadvantage:
■ more flip-flops
54
● One-hot counter
○ Initialization
■ Initialize one flip-flop to 1, and the others to 0
1 0 0 0 0
0 0 0
55
17
19-07-25
64
Count Sequence:
0000 -> 1000 -> 1100 -> 1110 -> 0111 -> 1011 ->1101 -> 0110 -> 0011 ->
1001 -> 0100 ->1010 -> 0101 -> 0010 -> 0001 -> repeat 65
Counts through 15 numbers, but in a strange order
18
19-07-25
67
19
19-07-25
Timing
69
20
19-07-25
Timing
70
71
21
19-07-25
● Critical path
○ The longest path between any inputs, outputs and flip-flops
○ Ex: What is the longest delay in this combinational circuit assuming that all gates
take 1ns and wires transmit data instantaneously (wire delay is zero)?
72
● Critical path
In other words, in the previous circuit, if we apply all inputs at time 0,
then by time 5ns, all the outputs have settled to their final values.
73
22
19-07-25
● All registers in digital devices (such as FPGAs) have defined signal timing requirements
○ Those requirements need to be met to allow registers to correctly capture data
● Setup time (tsu)
○ Time that the input should remain stable before the clock edge arrival
● Hold time (thold)
○ Time that the input should remain stable after the clock edge arrival
● Clock-to-output-delay (Clk-to-Q delay)
○ Time required for output to be available after setup time
If the data doesn't arrive tsu
before the clock edge or it
is not held for more than
thold the flip-flop might not
be able to record the right
value.
74
Timing - Metastability
● Definition
○ Metastability is a phenomenon that can cause system failure in digital devices,
including FPGAs
○ If a data signal transition violates a register’s tsu or thold requirements, the output
of the register may go into a metastable state.
○ In a metastable state, the register output hovers at a value between the high and
low states for some period of time
■ This means the output transition to a defined high or low state is delayed
beyond the specified tCO.
75
23
19-07-25
Timing - Metastability
● Understanding metastability
77
24
19-07-25
78
25