I'm new to Verilog, and I'm taking my first steps with FPGA "programming". I have a parametrized module definition similar to that:
module foobar #(
parameter BITS = 4
) (...);
reg[BITS - 1:0] counter = 0;
...
if (counter == |) begin
...
end
...
endmodule
and want to test at | whether all bits of counter are set (or unset). How to achieve that? Without parametrization, it would be easy by specifying, e.g. 4'b1111 (or 4'b0000).
Use the replicated concatenation operator. Check if all bits set:
if (counter == {BITS{1'b1}}) begin
Check if all bits cleared:
if (counter == {BITS{1'b0}}) begin
Alternately, with SystemVerilog features enabled:
if (counter == '1) begin // All set
if (counter == '0) begin // All cleared
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With