A temperature grader shows old grades in simulation. Find every way its function holds on to the past, and make the outputs follow all four inputs.
Hardware context: A package of two Gray code functions used on a 5-bit and an 8-bit port; and a temperature grader whose function reads two thresholds from its module. Fix the grader so both grades follow all four inputs.
A thermal monitor grades the temperature now, and the temperature it expects after a rise. The grade is 0 below lo_thr, 1 from lo_thr and 2 from hi_thr. Firmware retunes the thresholds while the chip runs. In simulation the grades lag behind: a retuned threshold has no effect, and a cool reading keeps a hot grade.
This is a Fix problem: the starter is the shipped design. It has more than one fault, and repairing only the first one you find still fails. The tests set the four inputs, then change one input per step and read both grades after each step.
Brief: combinational. level is the grade of temp. level_next is the grade of temp + rise, where the sum is not cut to 8 bits. Both outputs depend only on the present values of the four inputs.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
start | 32 | input of each check |
script | 120 | input of each check |
Full specification
module temp_grade (
input logic [7:0] temp, // the reading now
input logic [7:0] rise, // how much it is expected to rise
input logic [7:0] lo_thr, // at or above this: level 1
input logic [7:0] hi_thr, // at or above this: level 2
output logic [1:0] level, // the grade of temp
output logic [1:0] level_next // the grade of temp + rise
);
...
endmodule
| Value v | Grade |
|---|---|
| v >= hi_thr | 2 |
| v >= lo_thr and v < hi_thr | 1 |
| v < lo_thr and v < hi_thr | 0 |
| Output | v |
|---|---|
| level | temp |
| level_next | temp + rise, 0 to 510 |
Each test sets temp, rise, lo_thr and hi_thr, waits, then applies 12 steps. A step changes exactly one of the four inputs. The result holds level and level_next 1 ns after each step.
The thresholds can be equal or in the wrong order. The table still applies as written: hi_thr is tested first.
Examples
Example 1
The Thresholds Move While Temp Stays Still- Input
start: temp=50 rise=5 lo_thr=40 hi_thr=80; then hi_thr=45, hi_thr=60, lo_thr=55, lo_thr=30, hi_thr=52, lo_thr=51, hi_thr=90, lo_thr=10, hi_thr=50, lo_thr=60, hi_thr=70, lo_thr=20
- Output
level_step0 = 2, next_step0 = 2, level_step1 = 1, next_step1 = 1, level_step2 = 0, next_step2 = 1, level_step3 = 1, next_step3 = 1, level_step4 = 1, next_step4 = 2, level_step5 = 0, next_step5 = 2, level_step6 = 0, next_step6 = 1, level_step7 = 1, next_step7 = 1, level_step8 = 2, next_step8 = 2, level_step9 = 2, next_step9 = 2, level_step10 = 0, next_step10 = 0, level_step11 = 1, next_step11 = 1
temp is 50 and the forecast 55 throughout. Lowering hi_thr to 45 must lift both grades to 2 at once, with no change on temp or rise.
Example 2
The Reading Falls Below the Lower Threshold- Input
start: temp=90 rise=0 lo_thr=40 hi_thr=80; then temp=60, temp=30, temp=45, temp=10, temp=85, temp=39, temp=40, temp=79, temp=80, temp=0, temp=41, temp=20
- Output
level_step0 = 1, next_step0 = 1, level_step1 = 0, next_step1 = 0, level_step2 = 1, next_step2 = 1, level_step3 = 0, next_step3 = 0, level_step4 = 2, next_step4 = 2, level_step5 = 0, next_step5 = 0, level_step6 = 1, next_step6 = 1, level_step7 = 1, next_step7 = 1, level_step8 = 2, next_step8 = 2, level_step9 = 0, next_step9 = 0, level_step10 = 1, next_step10 = 1, level_step11 = 0, next_step11 = 0
From 60 to 30 the grade must drop from 1 to 0. A function that assigns nothing on that path shows the old grade.
Example 3
Only the Forecast Is High- Input
start: temp=20 rise=0 lo_thr=40 hi_thr=80; then rise=25, rise=70, rise=10, temp=35, rise=4, rise=5, rise=45, temp=10, rise=29, rise=30, rise=69, rise=70
- Output
level_step0 = 0, next_step0 = 1, level_step1 = 0, next_step1 = 2, level_step2 = 0, next_step2 = 0, level_step3 = 0, next_step3 = 1, level_step4 = 0, next_step4 = 0, level_step5 = 0, next_step5 = 1, level_step6 = 0, next_step6 = 2, level_step7 = 0, next_step7 = 1, level_step8 = 0, next_step8 = 0, level_step9 = 0, next_step9 = 1, level_step10 = 0, next_step10 = 1, level_step11 = 0, next_step11 = 2
temp is 20 and its grade is 0. With rise at 70 the forecast is 90 and its grade is 2. The two calls must not share a result.
Constraints and Contract
- Inputs are known 0/1 values. A step changes one input; the others hold.
- Keep the module name and the ports. Keep the logic combinational: no clock, no storage.
Hints
Hint 1
List every signal the function reads. Then list what the block that calls it reads. Which signals appear only in the first list?
Hint 2
Follow one call where v is below both thresholds. Which statement gives the grade its value on that path?
Hint 3
The function is called twice in a row. Ask whether the second call starts from a clean variable or from what the first call left.
What the grader checks: Six directed and ten seeded scripts set the four inputs and then change one input per step, twelve steps each. Both grades after every step are compared with an independent model. Passing shows the outputs follow every input on these scripts on Icarus Verilog. This problem has no synthesis check.
16 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone