Altera_Forum
Honored Contributor
15 years agoVHDL Numeric Type Conversion
I am using a bunch of variables to do some math. These variables, X and Y coordinates, are converted to different numeric types for ease of math operations. The outputs, Xm and Ym, are SLV's and depend on the intermediary variables Xc and Yc. Xm and Ym are simulated correctly using Quartus II 9.1 native simulator, but the intermediary variables Xp and Yp, who also depend on Xc and Yc, are not. How could this be? Here are the relevant snipets of my code:
--- use ieee.numeric_std.all; ... generic(dst_max : positive := 300000); ... Xm, Ym : out std_logic_vector(19 downto 0); ... variable d1, d2, d3, d4 : natural range 0 to dst_max; variable Xc, Yc, Xc1, Yc1, Xp, Yp : integer range -dst_max to dst_max; variable Xc_sv, Yc_sv, Xc_sv1, Yc_sv1 : signed(19 downto 0); ... elsif (d2 /= 0) and (d4 /= 0) then Xc1 := (d4 - d2); Xc_sv1 := to_signed(Xc1, 20); Xc_sv := Xc_sv1(19) & Xc_sv1(19 downto 1); -- shift right by 1 to divide by 2 Xc := to_integer(Xc_sv); else Xc := Xp; -- use previous end if; ... elsif (d1 /= 0) and (d3 /= 0) then Yc1 := (d3 - d1); Yc_sv1 := to_signed(Yc1, 20); Yc_sv := Yc_sv1(19) & Yc_sv1(19 downto 1); -- shift right by 1 to divide by 2 Yc := to_integer(Yc_sv); else Yc := Yp; end if; Xp := Xc; -- update previous Yp := Yc; -- Xp and Yp DO NOT SIMULATE CORRECTLY Xm <= std_logic_vector(to_signed(-Xc, 20)); -- move Ym <= std_logic_vector(to_signed(-Yc, 20)); -- Xm and Ym SIMULATE CORRECTLY --- Simulation Results: d1 = 1955, d2 = 300000, d3 = 158100, d4 = 23456 Xp should be -138272, but is 430016 Yp should be 78072, but is -369448 Xm is 138272 (correct) Ym is -78072 (correct) Xc* and Yc* could not be displayed by the simulator