00:00:00.000 Two sensors, one display A machine has two temperature sensors. Sensor A reports zero: no overtemperature. Sensor B reports one: overtemperature. The display has only one output, so an operator chooses which sensor to view. The sensors have already converted their readings into digital flags. Our job is to select a flag. This small circuit lets us follow a complete first design: define the requirement, describe the hardware, and test whether the connections do what we intended. 00:00:36.730 Choose the source, then read its value Call the data inputs A and B, the selection signal sel, and the output selected. Our rule is simple. When sel is zero, the output follows A. When sel is one, the output follows B. This is a multiplexer, usually called a mux. Selecting A does not mean producing a one. If A currently holds zero, the output must be zero. The selection signal chooses a source; the value at that source determines the output. 00:01:16.880 Modules and ports define the boundary We name the module channel select one bit. A module is a named hardware description, and its ports are the connections to the surrounding design. Input and output declare signal direction. Every port in this example is one bit wide. The suffixes underscore i and underscore o are our naming convention for inputs and outputs. They are not language keywords. Recognizing this boundary helps you separate the module's interface from the logic described inside it. 00:01:57.920 Assign describes a continuous relationship The function fits in one continuous assignment. The expression before the question mark is the condition. The two expressions separated by the colon are the values to choose between. A one selects B; a zero selects A. Assign describes a relationship that remains in effect. When an input changes, the simulator reevaluates the relationship. We begin with settled zeros and ones. Unknown and high-impedance values need the four-state model introduced in a later lesson. 00:02:35.670 One RTL statement describes a selection Suppose A is one and B is zero. With sel set to zero, the output should be one. Change sel to one, and the output should follow B to zero. The requirement depends only on the current inputs. It does not ask us to retain an earlier result, so this example needs no register. The highlighted path illustrates the function. It does not measure propagation delay. 00:03:08.300 Instances connect the module into a design Now both a display and a logger need the selected result. We can instantiate the module twice, naming the instances u panel and u logger. An instance is an occurrence of the module within a larger design. Here, the same A, B and selection signals connect to both instances. Their outputs connect to the display and logger. In a named port connection, the name after the dot identifies the module's port. The signal inside parentheses comes from the surrounding design. 00:03:50.850 Connections determine the relationship Writing one instance before the other does not make the second wait for the first. Look at the connections: both receive the same inputs directly. The first output does not feed the second input. Reordering the declarations therefore does not change the settled function. Two source instances also do not guarantee two independent physical circuits. Synthesis may share equivalent logic. Physical independence would require additional implementation requirements and checks beyond this introductory example. 00:04:29.840 A testbench drives and checks the circuit A testbench is the simulation environment. It drives inputs into the design under test, then compares the actual output with an expected value. Our test applies the inputs, waits with hash five, and reads the result. The testbench defines a time unit of one nanosecond, so this advances simulation by five nanoseconds. It schedules an observation. It does not specify a fixed five-nanosecond chip delay. There is no clock in this example, so it does not mean five clock cycles. 00:05:08.920 The waveform places four tests in time Read the waveform from left to right. During the first interval, A is zero and B is one. We select A, so the output is zero. Next, A becomes one and B becomes zero. A remains selected, so the output becomes one. In the last two intervals, we select B and the output follows B. These four cases deliberately give A and B different values. First identify the selected source, then read its value to predict the answer. 00:05:45.660 Swap A and B without changing the test Now deliberately exchange A and B on the two sides of the colon. Keep the requirement and the testbench unchanged. The first case expects zero, but the swapped circuit produces one. All four directed cases fail. This counterexample tells us more than a passing message alone: the test can distinguish this particular wiring error. Expected answers must come from the requirement. Changing them merely to match a broken implementation would defeat the purpose of the test. 00:06:24.020 Only four binary rows expose the swap Each of the three one-bit inputs can be zero or one, giving eight combinations. The correct circuit passes every row. The swapped circuit fails only four. Why not eight? When A and B hold the same value, selecting either source gives the same output, hiding the error. Passing all eight rows supports a specific claim: the settled binary function matches this truth table. It does not cover unknown values, physical delay, or security attacks. 00:07:02.380 Compile, simulate and synthesize The source package separates the tool steps. First, Icarus Verilog compiles the design and testbench, checking that the descriptions can be processed. Then vvp runs the simulation and produces comparison results and a VCD waveform. Finally, Yosys synthesizes the design so we can inspect its logic structure. These steps answer different questions. Compilation alone does not establish functional correctness. Passing simulation does not mean that a physical chip has been implemented. 00:07:39.560 The synthesized structure contains one mux The actual Yosys run produces one generic mux cell and no flip-flop cell. That matches the requirement: current inputs determine the current output, with no stored state. The tool also checks the resulting structure. This result has not been mapped to a particular process library, however. It cannot establish final area, speed, or power. Those questions require further synthesis settings and physical implementation information. 00:08:08.010 What changes when the requirement changes? Suppose the operator now asks to see B when sel is zero. This is a changed requirement, rather than a bug fix under the old rule. Update the RTL, the testbench's expected answers, and the panel labels together. The circuit we previously called swapped satisfies this new requirement. Correctness depends on the intended behavior. Looking at the assignment by itself cannot tell us which source the operator wanted a zero to select. The surrounding requirement supplies that context. 00:08:46.980 Rerun the example and keep the evidence Return to the article to download the full example. The correct and swapped implementations use the same module name, so compile them separately rather than including both in one design. The script runs four directed cases, the eight-row truth table, and the two-instance connection test. It also checks that the swapped implementation is rejected. Keeping the logs, waveform and synthesis result makes the work reproducible and gives you a useful comparison when you change the design. 00:09:21.490 Start with the requirement and follow the signals We started with a small selection requirement and followed it through module ports, continuous assignment, instance connections and reproducible tests. Use the same reading order when you meet another RTL design. Ask what the inputs and outputs represent, trace their relationship, then choose a test that can distinguish correct behavior from a plausible mistake. The next lesson introduces bit representation and four-state logic, giving us a way to interpret simulation results beyond ordinary zeros and ones.