Integer overflow in OneWireBus due to c_ClkFrequency defined as integer
I couldn't read the unique ID value, using the command vfc_hd_scan
, from the DS18B20U+ chip because the 1-wire bus module didn't work in my project. In VfcHdTop.sv file, c_ClkFrequency
is defined as an integer and passed as a parameter g_ClkFrequency
value to the System module, which further passes it to the UniqueIdTemp.sv and OneWireBus.sv modules. The integer overflow occurred during the multiplication of two integers in the time delay expressions in the OneWireBus.sv module, resulting in incorrect evaluation. This issue appeared in the project compiled using Quartus Prime Pro 21.2.
// Time delays are based on recommended values from Maxim AN126
localparam int c_DlyCntBits = $clog2(int'((960 * g_ClkFrequency) / 1e6) + 1);
localparam c_960us = (c_DlyCntBits)'(int'((960 * g_ClkFrequency) / 1e6));
localparam c_480us = (c_DlyCntBits)'(int'((480 * g_ClkFrequency) / 1e6));
localparam c_410us = (c_DlyCntBits)'(int'((410 * g_ClkFrequency) / 1e6));
localparam c_70us = (c_DlyCntBits)'(int'(( 70 * g_ClkFrequency) / 1e6));
localparam c_64us = (c_DlyCntBits)'(int'(( 64 * g_ClkFrequency) / 1e6));
localparam c_55us = (c_DlyCntBits)'(int'(( 55 * g_ClkFrequency) / 1e6));
localparam c_10us = (c_DlyCntBits)'(int'(( 10 * g_ClkFrequency) / 1e6));
localparam c_0us = (c_DlyCntBits)'(int'(( 0 * g_ClkFrequency) / 1e6));
Edited by Stasa Kostic