Skip to content
code0.HDL

06Verification

Let a fault override the fan

Problem

Intended behavior. FanControl picks a fan speed from an 8-bit temperature: below 50 gives speed 0, 50 to 79 gives 1, and 80 or more gives 2. When fault is high, the temperature reading cannot be trusted, so the fan must run at speed 3 whatever temp says.

Current behavior. The starter compiles and the three fault-free rows are correct. The faulty row prints speed 0, as if fault were low.

Task. Find why the fault has no effect and fix it. Keep the thresholds, the speed encodings, and the ports.

Read the starter

Two when blocks drive the same output, io.speed. For the input temp = 30, fault = true, list every connection to io.speed whose condition holds, in the order they appear in the source. Then apply the rule that decides between connections to one sink.

Predict before running

Predict the four printed rows for the starter. Then predict a row the public run does not print: temp = 90, fault = true. Your fix must give 3 for that row too.

Run and explain

The starter prints 0, 1, 2, and 0. The fault block does connect 3, but the temperature chain is written after it and always connects something, because .otherwise covers every remaining case. The later connection wins, so the fault block never takes effect. A corrected design prints 0, 1, 2, and 3.

Check your repair against the unprinted row. A fault test placed late inside the chain, after the temperature branches, makes the cold row print 3 while a hot faulty input still follows the temperature.

Completion check

  • With fault high, speed is 3 for every temperature from 0 to 255.
  • With fault low, the boundaries hold exactly: 49 gives 0, 50 gives 1, 79 gives 1, and 80 gives 2.
  • speed is driven on every path.

Progressive hints

Hint 1

For a faulty input, both when blocks connect a value. Only one connection can reach the output; position in the source decides which one.

Hint 2

The fault decision must be the last connection that holds, or it must be tested before any temperature condition can claim the output. Either arrangement works; mixing it in after a temperature branch does not.

Concept

when does not express importance. Chisel collects every guarded connection to a sink and resolves them in program order, so priority is written by position: a .elsewhen chain takes its first true branch, and between separate blocks the later one wins.

Transfer experiment

Imagine a second override, boost, that forces speed 2 but must yield to fault. Decide where its block goes relative to the fault block and the chain, and predict the speed for temp = 10 with both inputs high.

Review this concept
Ready

CheerpJ runs Chisel in your browser. A cold Run downloads about 14.5 MB of Java and 47 MB of JARs. Compilation can take a minute. Licenses

Main.scala