WEBVTT

1
00:00:00.000 --> 00:00:02.520
A machine has two temperature sensors.

2
00:00:03.340 --> 00:00:07.140
Sensor A reports zero: no overtemperature.

3
00:00:07.920 --> 00:00:10.820
Sensor B reports one: overtemperature.

4
00:00:11.680 --> 00:00:17.400
The display has only one output, so an
operator chooses which sensor to view.

5
00:00:18.280 --> 00:00:22.060
The sensors have already converted their
readings into digital flags.

6
00:00:22.840 --> 00:00:24.680
Our job is to select a flag.

7
00:00:24.680 --> 00:00:28.580
This small circuit lets us follow a
complete

8
00:00:28.580 --> 00:00:31.380
first design: define the requirement,

9
00:00:32.000 --> 00:00:36.260
describe the hardware, and test whether
the connections do what we intended.

10
00:00:36.730 --> 00:00:41.070
Call the data inputs A and B, the
selection

11
00:00:41.070 --> 00:00:44.930
signal sel, and the output selected.

12
00:00:46.030 --> 00:00:47.290
Our rule is simple.

13
00:00:48.010 --> 00:00:51.790
When sel is zero, the output follows A.

14
00:00:52.490 --> 00:00:55.930
When sel is one, the output follows B.

15
00:00:56.730 --> 00:01:00.550
This is a multiplexer, usually called a
mux.

16
00:01:01.650 --> 00:01:05.570
Selecting A does not mean producing a one.

17
00:01:05.570 --> 00:01:09.850
If A currently holds zero, the output must
be zero.

18
00:01:10.630 --> 00:01:12.970
The selection signal chooses a source;

19
00:01:13.590 --> 00:01:16.430
the value at that source determines the
output.

20
00:01:16.880 --> 00:01:20.160
We name the module channel select one bit.

21
00:01:21.100 --> 00:01:24.180
A module is a named hardware description,

22
00:01:24.680 --> 00:01:28.660
and its ports are the connections to the
surrounding design.

23
00:01:29.620 --> 00:01:32.940
Input and output declare signal direction.

24
00:01:33.920 --> 00:01:36.920
Every port in this example is one bit
wide.

25
00:01:38.000 --> 00:01:42.600
The suffixes underscore i and underscore o
are

26
00:01:42.600 --> 00:01:45.820
our naming convention for inputs and
outputs.

27
00:01:45.820 --> 00:01:48.340
They are not language keywords.

28
00:01:49.660 --> 00:01:54.240
Recognizing this boundary helps you
separate the module's

29
00:01:54.240 --> 00:01:57.600
interface from the logic described inside
it.

30
00:01:57.920 --> 00:02:01.220
The function fits in one continuous
assignment.

31
00:02:01.940 --> 00:02:05.120
The expression before the question mark is
the condition.

32
00:02:05.860 --> 00:02:10.820
The two expressions separated by the colon
are the values to choose between.

33
00:02:11.660 --> 00:02:14.900
A one selects B; a zero selects A.

34
00:02:16.040 --> 00:02:19.760
Assign describes a relationship that
remains in effect.

35
00:02:20.400 --> 00:02:24.920
When an input changes, the simulator
reevaluates the relationship.

36
00:02:24.920 --> 00:02:28.560
We begin with settled zeros and ones.

37
00:02:29.320 --> 00:02:32.180
Unknown and high-impedance values need

38
00:02:32.180 --> 00:02:35.200
the four-state model introduced in a later
lesson.

39
00:02:35.670 --> 00:02:39.270
Suppose A is one and B is zero.

40
00:02:39.970 --> 00:02:43.850
With sel set to zero, the output should be
one.

41
00:02:44.490 --> 00:02:49.470
Change sel to one, and the output should
follow B to zero.

42
00:02:50.450 --> 00:02:53.730
The requirement depends only on the
current inputs.

43
00:02:54.370 --> 00:03:01.050
It does not ask us to retain an earlier
result, so this example needs no register.

44
00:03:01.050 --> 00:03:05.010
The highlighted path illustrates the
function.

45
00:03:05.570 --> 00:03:07.790
It does not measure propagation delay.

46
00:03:08.300 --> 00:03:13.360
Now both a display and a logger need the
selected result.

47
00:03:13.980 --> 00:03:21.540
We can instantiate the module twice,
naming the instances u panel and u logger.

48
00:03:22.420 --> 00:03:27.480
An instance is an occurrence of the module
within a larger design.

49
00:03:28.420 --> 00:03:34.560
Here, the same A, B and selection signals
connect to both instances.

50
00:03:34.560 --> 00:03:38.480
Their outputs connect to the display and
logger.

51
00:03:39.320 --> 00:03:45.100
In a named port connection, the name after
the dot identifies the module's port.

52
00:03:46.160 --> 00:03:50.320
The signal inside parentheses comes from
the surrounding design.

53
00:03:50.850 --> 00:03:56.950
Writing one instance before the other does
not make the second wait for the first.

54
00:03:57.610 --> 00:04:01.650
Look at the connections: both receive the
same inputs directly.

55
00:04:02.610 --> 00:04:05.930
The first output does not feed the second
input.

56
00:04:06.710 --> 00:04:10.910
Reordering the declarations therefore does
not change the settled function.

57
00:04:11.950 --> 00:04:18.010
Two source instances also do not guarantee
two independent physical circuits.

58
00:04:18.010 --> 00:04:21.570
Synthesis may share equivalent logic.

59
00:04:22.410 --> 00:04:25.910
Physical independence would require
additional implementation

60
00:04:25.910 --> 00:04:29.390
requirements and checks beyond this
introductory example.

61
00:04:29.840 --> 00:04:32.580
A testbench is the simulation environment.

62
00:04:33.140 --> 00:04:36.540
It drives inputs into the design under
test,

63
00:04:36.840 --> 00:04:40.980
then compares the actual output with an
expected value.

64
00:04:41.980 --> 00:04:47.900
Our test applies the inputs, waits with
hash five, and reads the result.

65
00:04:48.700 --> 00:04:52.320
The testbench defines a time unit of one
nanosecond,

66
00:04:52.740 --> 00:04:56.220
so this advances simulation by five
nanoseconds.

67
00:04:56.840 --> 00:04:58.200
It schedules an observation.

68
00:04:58.200 --> 00:05:03.140
It does not specify a fixed
five-nanosecond chip delay.

69
00:05:03.940 --> 00:05:08.360
There is no clock in this example, so it
does not mean five clock cycles.

70
00:05:08.920 --> 00:05:11.580
Read the waveform from left to right.

71
00:05:12.240 --> 00:05:16.280
During the first interval, A is zero and B
is one.

72
00:05:16.920 --> 00:05:20.160
We select A, so the output is zero.

73
00:05:21.100 --> 00:05:24.300
Next, A becomes one and B becomes zero.

74
00:05:25.060 --> 00:05:28.380
A remains selected, so the output becomes
one.

75
00:05:29.240 --> 00:05:34.300
In the last two intervals, we select B and
the output follows B.

76
00:05:34.300 --> 00:05:39.380
These four cases deliberately give A and B
different values.

77
00:05:40.080 --> 00:05:45.160
First identify the selected source, then
read its value to predict the answer.

78
00:05:45.660 --> 00:05:51.120
Now deliberately exchange A and B on the
two sides of the colon.

79
00:05:51.820 --> 00:05:54.920
Keep the requirement and the testbench
unchanged.

80
00:05:55.960 --> 00:06:00.540
The first case expects zero, but the
swapped circuit produces one.

81
00:06:01.280 --> 00:06:03.400
All four directed cases fail.

82
00:06:04.340 --> 00:06:08.640
This counterexample tells us more than a
passing message alone:

83
00:06:09.280 --> 00:06:13.140
the test can distinguish this particular
wiring error.

84
00:06:14.040 --> 00:06:17.240
Expected answers must come from the
requirement.

85
00:06:18.020 --> 00:06:20.560
Changing them merely to match a broken

86
00:06:20.560 --> 00:06:23.460
implementation would defeat the purpose of
the test.

87
00:06:24.020 --> 00:06:30.220
Each of the three one-bit inputs can be
zero or one, giving eight combinations.

88
00:06:31.180 --> 00:06:33.420
The correct circuit passes every row.

89
00:06:34.100 --> 00:06:36.520
The swapped circuit fails only four.

90
00:06:37.440 --> 00:06:38.460
Why not eight?

91
00:06:39.320 --> 00:06:43.440
When A and B hold the same value,
selecting either

92
00:06:43.440 --> 00:06:46.640
source gives the same output, hiding the
error.

93
00:06:47.520 --> 00:06:51.140
Passing all eight rows supports a specific
claim:

94
00:06:51.140 --> 00:06:55.680
the settled binary function matches this
truth table.

95
00:06:56.420 --> 00:07:01.840
It does not cover unknown values, physical
delay, or security attacks.

96
00:07:02.380 --> 00:07:05.320
The source package separates the tool
steps.

97
00:07:05.980 --> 00:07:10.440
First, Icarus Verilog compiles the design
and testbench,

98
00:07:10.700 --> 00:07:12.860
checking that the descriptions can be
processed.

99
00:07:13.700 --> 00:07:20.640
Then vvp runs the simulation and produces
comparison results and a VCD waveform.

100
00:07:21.500 --> 00:07:27.040
Finally, Yosys synthesizes the design so
we can inspect its logic structure.

101
00:07:27.800 --> 00:07:29.800
These steps answer different questions.

102
00:07:29.800 --> 00:07:34.400
Compilation alone does not establish
functional correctness.

103
00:07:34.960 --> 00:07:38.960
Passing simulation does not mean that a
physical chip has been implemented.

104
00:07:39.560 --> 00:07:45.240
The actual Yosys run produces one generic
mux cell and no flip-flop cell.

105
00:07:45.840 --> 00:07:48.320
That matches the requirement: current
inputs

106
00:07:48.320 --> 00:07:51.260
determine the current output, with no
stored state.

107
00:07:52.060 --> 00:07:54.060
The tool also checks the resulting
structure.

108
00:07:54.900 --> 00:07:58.440
This result has not been mapped to a
particular process library, however.

109
00:07:59.060 --> 00:08:02.020
It cannot establish final area, speed, or
power.

110
00:08:02.720 --> 00:08:04.780
Those questions require further synthesis

111
00:08:04.780 --> 00:08:07.320
settings and physical implementation
information.

112
00:08:08.010 --> 00:08:12.810
Suppose the operator now asks to see B
when sel is zero.

113
00:08:13.890 --> 00:08:18.430
This is a changed requirement, rather than
a bug fix under the old rule.

114
00:08:19.230 --> 00:08:25.250
Update the RTL, the testbench's expected
answers, and the panel labels together.

115
00:08:26.430 --> 00:08:31.210
The circuit we previously called swapped
satisfies this new requirement.

116
00:08:32.110 --> 00:08:34.990
Correctness depends on the intended
behavior.

117
00:08:34.990 --> 00:08:39.150
Looking at the assignment by itself cannot
tell us

118
00:08:39.150 --> 00:08:42.630
which source the operator wanted a zero to
select.

119
00:08:43.370 --> 00:08:46.230
The surrounding requirement supplies that
context.

120
00:08:46.980 --> 00:08:49.820
Return to the article to download the full
example.

121
00:08:50.440 --> 00:08:55.040
The correct and swapped implementations
use the same module name,

122
00:08:55.540 --> 00:08:59.380
so compile them separately rather than
including both in one design.

123
00:09:00.400 --> 00:09:03.880
The script runs four directed cases, the
eight-row

124
00:09:03.880 --> 00:09:07.300
truth table, and the two-instance
connection test.

125
00:09:07.980 --> 00:09:11.400
It also checks that the swapped
implementation is rejected.

126
00:09:12.380 --> 00:09:17.000
Keeping the logs, waveform and synthesis
result makes the work

127
00:09:17.000 --> 00:09:21.120
reproducible and gives you a useful
comparison when you change the design.

128
00:09:21.490 --> 00:09:26.810
We started with a small selection
requirement and followed it through module

129
00:09:26.810 --> 00:09:33.050
ports, continuous assignment, instance
connections and reproducible tests.

130
00:09:33.950 --> 00:09:38.190
Use the same reading order when you meet
another RTL design.

131
00:09:38.850 --> 00:09:43.490
Ask what the inputs and outputs represent,
trace their relationship,

132
00:09:44.010 --> 00:09:49.550
then choose a test that can distinguish
correct behavior from a plausible mistake.

133
00:09:49.550 --> 00:09:55.570
The next lesson introduces bit
representation and four-state logic,

134
00:09:56.090 --> 00:10:01.470
giving us a way to interpret simulation
results beyond ordinary zeros and ones.

