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
- Immediate Assertions: Evaluated at a specific point in time during simulation.
- 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:
verilogassert (condition) else $fatal("Error message");
Example:
verilogmodule 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
resetsignal 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:
verilogsequence seq_name; // Define sequence endsequence property prop_name; // Define property using sequence endproperty assert property (prop_name) else $fatal("Error message");
Example:
verilogmodule 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_changechecks ifdatais not equal to8'h00whenresetis low. - The property
p_data_changespecifies 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.
verilogsequence seq_name; // Define sequence endsequenceProperty: Specifies a condition that uses sequences and can be checked with assertions.
verilogproperty 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.
verilogassume property (prop_name);
Assume and Assume Property
Assumptions state what the design is expected to do, and are typically used in formal verification.
verilogassume property (p_data_change);
Cover Property
Cover properties are used to check whether certain conditions are met and are useful for coverage analysis.
verilogcover property (p_data_change);
Example of Advanced Assertions
Here’s an example combining sequences, properties, and assertions:
verilogmodule 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_changechecks ifdatachanges from8'h00after one clock cycle whenresetis low. - The property
p_data_changeuses 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.