Menu
Coddy logo textTech

Raise a Threshold Alarm

Part of the RTL Design & Verification section of Coddy's Verilog journey. Lesson 35 of 38.

challenge icon

Challenge

Hard

Build one Sample Monitor over five steps. Drive combinational alarm high whenever total is at least unsigned limit, including equality. The alarm reflects the updated total after each edge and follows limit changes. limit=0 makes alarm high even when total=0. Preserve all accumulation, enable, clear and counting behavior. Keep everything from the previous steps, including its testbench and earlier output behavior. All input values are known. Scenarios contain at most 40 edges, so the total fits in 16 bits. The fixed testbench prints total for scenarios 1-9, total and count for scenarios 10-12, and total, count and alarm for scenarios 13-15. Only scenarios enabled for this step are graded.

Complete design.v and preserve its module names and ports. The locked testbench.v supplies input changes and prints the outputs after they settle. It chooses a scenario using a simulator argument such as +CASE=1; no standard input is required. Do not add printing, delays or simulation termination to the design. Expected output is one row of decimal values per observation, separated by one space and ending with a newline.

Try it yourself

module dut(input clk,rst,en,clear, input [7:0] data, input [15:0] limit, output reg [15:0] total, output reg [3:0] count, output alarm);
    always @(posedge clk)begin
        if(rst || clear)begin total<=0;count<=0;end
        else if(en)begin
            total<=total+data;
            if(count!=15)count<=count+4'd1;
        end
    end
    assign alarm=0;
endmodule

All lessons in RTL Design & Verification

Practice on your own: Online Verilog compiler