我很難過去幾天我一直在試圖解決我的VHDL中的鑄造錯誤。我的代碼附在下面。VHDL Casting Error
它將正確評估if語句,但不會將新值分配給最小或最大變量。我知道這一點,因爲我評論和測試了函數的不同方面。
FYI。類型t_battery_data
包含一個std_logic_vectors(15 downto 0)
的數組,這是我在下面的函數中比較的電壓。
我不知道爲什麼這樣做。關於我在網上搜索時可以找到的所有內容包括我已經完成的ieee.numeric_std
庫。
仍難倒。任何建議將不勝感激。謝謝!
function cell_delta_voltage_counts(
bat_data: t_battery_data
) return integer is
constant POS_INFINITY: integer:= 2 ** 16 - 1;
constant NEG_INFINITY: integer:= 0;
variable min: integer range 0 to 2 ** 16 - 1:= POS_INFINITY-5;
variable max: integer range 0 to 2 ** 16 - 1:= NEG_INFINITY;
begin
for i in 0 to NUM_CELLS-1 loop
if (to_integer(unsigned(bat_data.cell_readings(i).voltage)) < min) then
min := to_integer(unsigned(bat_data.cell_readings(i).voltage));
end if;
if (to_integer(unsigned(bat_data.cell_readings(i).voltage)) > max) then
max := to_integer(unsigned(bat_data.cell_readings(i).voltage));
end if;
end loop;
return max - min;
end function cell_delta_voltage_counts;