techmore.in

Verilog Assertions

Verilog Assertions are used to check the correctness of designs and verify that certain conditions hold true throughout the simulation. Assertions help in detecting errors, verifying properties, and ensuring that designs behave as expected.

Types of Assertions

  1. Immediate Assertions: Evaluated at a specific point in time during simulation.
  2. Concurrent Assertions: Monitored over time, checking conditions across multiple clock cycles.

Immediate Assertions

Immediate assertions are used for simple checks and are evaluated in the current simulation time step. They are typically used for sanity checks and simple properties.

Syntax:

verilog
assert (condition) else $fatal("Error message");

Example:

verilog
module test; reg clk; reg reset; initial begin clk = 0; reset = 1; #10 reset = 0; end always #5 clk = ~clk; // Immediate assertion always @(posedge clk) begin assert (reset == 1) else $fatal("Reset should be high on clock edge"); end endmodule

In this example:

  • The assertion checks that the reset signal is high at every positive edge of the clock.
  • If the condition fails, the simulation will halt and print an error message.

Concurrent Assertions

Concurrent assertions are used to check conditions over time and are evaluated across multiple clock cycles. They are more complex and powerful compared to immediate assertions.

Syntax:

verilog
sequence seq_name; // Define sequence endsequence property prop_name; // Define property using sequence endproperty assert property (prop_name) else $fatal("Error message");

Example:

verilog
module test; reg clk; reg reset; reg [7:0] data; initial begin clk = 0; reset = 1; data = 8'h00; #10 reset = 0; #20 data = 8'hFF; end always #5 clk = ~clk; // Sequence definition sequence seq_data_change; @(posedge clk) !reset && (data != 8'h00); endsequence // Property definition property p_data_change; seq_data_change; endproperty // Concurrent assertion assert property (p_data_change) else $fatal("Data should change when reset is low"); endmodule

In this example:

  • The sequence seq_data_change checks if data is not equal to 8'h00 when reset is low.
  • The property p_data_change specifies that this sequence should hold true.
  • The assertion verifies the property over time, and if it fails, it prints an error message.

SystemVerilog Assertion Constructs

SystemVerilog extends Verilog assertions with more advanced constructs:

Sequence and Property

  • Sequence: Defines a temporal pattern or condition to be checked over multiple clock cycles.

    verilog
    sequence seq_name; // Define sequence endsequence
  • Property: Specifies a condition that uses sequences and can be checked with assertions.

    verilog
    property prop_name; // Define property using sequence endproperty

Assumption

Assumptions are used to specify expected behavior that is assumed to be true. They are used to guide formal verification tools.

verilog
assume property (prop_name);

Assume and Assume Property

Assumptions state what the design is expected to do, and are typically used in formal verification.

verilog
assume property (p_data_change);

Cover Property

Cover properties are used to check whether certain conditions are met and are useful for coverage analysis.

verilog
cover property (p_data_change);

Example of Advanced Assertions

Here’s an example combining sequences, properties, and assertions:

verilog
module test; reg clk; reg reset; reg [7:0] data; initial begin clk = 0; reset = 1; data = 8'h00; #10 reset = 0; #20 data = 8'hFF; end always #5 clk = ~clk; // Sequence definition sequence seq_data_change; @(posedge clk) !reset ##1 (data != 8'h00); endsequence // Property definition property p_data_change; seq_data_change; endproperty // Concurrent assertion assert property (p_data_change) else $fatal("Data should change when reset is low"); // Cover property cover property (p_data_change); endmodule

In this example:

  • The sequence seq_data_change checks if data changes from 8'h00 after one clock cycle when reset is low.
  • The property p_data_change uses this sequence.
  • The assertion checks the property, and the cover statement helps in coverage analysis.

Assertions in Verilog and SystemVerilog provide powerful mechanisms to verify that designs behave correctly and meet the expected conditions throughout simulation. They help catch errors early and ensure the robustness of digital designs.