Toggle coverage is a type of code coverage that measures the percentage of signal transitions observed during the simulation. Here's an example of toggle coverage RTL code:
module toggle_circuit(input clk, input reset, output reg out); reg [7:0] counter = 8'h00; always @(posedge clk) begin if(reset) begin counter <= 8'h00; end else begin counter <= counter + 1; end end always @(posedge clk) begin out <= ~out; end endmodule
In this example, the toggle_circuit module has a counter that increments on the rising edge of the clock signal, and an output signal that toggles on every rising edge of the clock. The reset signal clears the counter back to zero.
To determine toggle coverage, a testbench would need to be created that stimulates the signals in a way that results in a high number of transitions for the output signal.
Here's an example of a SystemVerilog testbench that could be used to achieve toggle coverage:
module toggle_circuit_tb(); reg clk = 0; reg reset = 0; wire out; toggle_circuit dut(clk, reset, out); initial begin $monitor("Out = %b", out); reset = 1; #10; reset = 0; end always #5 clk = ~clk; endmodule
In this testbench, the reset signal is
initially set high to clear the counter. The monitor task displays the current value of the out signal in the console. The always block toggles the clock signal every five units of time.
Running this testbench would result in a high number of transitions for the output signal, thus achieving high toggle coverage percentage. If test cases were added that didn't result in a high number of transitions for the output signal, the toggle coverage percentage would decrease accordingly.