我想为计数器设置一个常量的大小:
localparam MAX_COUNT = ((debounce_per_ms * clk_freq)) + 1;
parameter MAX_COUNT_UPPER = $rtoi($floor($log10(MAX_COUNT)/$log10(2)));
这适用于 XST (ise) 和验证器,但在 Icarus 中我遇到了这个错误:
src/button_deb.v:20: error: $rtoi() is not a constant system function.
我可以使用“整数”类型来解决这个问题:
parameter integer MAX_COUNT_UPPER = $floor($log10(MAX_COUNT)/$log10(2));
但这在验证器中给了我一个警告:
$ verilator -cc src/button_deb.v
%Warning-REALCVT: src/button_deb.v:20: Implicit conversion of real to integer
%Warning-REALCVT: Use "/* verilator lint_off REALCVT */" and lint_on around source to disable this message.
%Error: Exiting due to 1 warning(s)
%Error: Command Failed /usr/local/bin/verilator_bin -cc src/button_deb.v
你认为有一个好方法可以做到这一点,并与 Icarus、verilator 和 Xst 兼容吗?