I am using a vhdl conversion package from freemodelfoundry.com, conversions.vhd. The function I am having a problem with is to_hex_str(slv,int). The simulation stops saying
Value 3 is out of valid range : 1 TO 2 of subtype of integer Simulation stopped when executing process: IRIG_TB.vhd:CTPControl on line 601 in file "C:/Arius/Boards/IRIG-B/FPGA/IRIG-B-X/ conversions.vhd"
function to_hex_str(x : std_logic_vector; rtn_len : natural := 0; justify : justify_side := right; basespec : b_spec := yes) return string is
When I look the error line, it is "ptr := ptr + 1;" which obviously could be running out of bounds. But looking at the code, the delclaration of ptr is based on the same information that controls the loop that is executing the statement, "ptr := ptr + 1;" I don't see any way for it to be assigning ptr out of bounds.
It gets trickier. I tried stripping my code down to the minimum that would cause the error and it very quickly went away. I am passing this function two parameters and allowing two to default. I don't see how anything in my code could cause a failure inside this function.
So now I am pretty stumped. I tried adding some debug statements, but they only told me that it was crapping out and the details that might actually tell me why can't be investigated... like what range is being assigned to ptr and why?
variable nxt : positive := nextmultof(x'length,4); variable int : std_logic_vector(1 to nxt):= (others => '0'); variable ptr : positive range 1 to (nxt/4)+1 := 1;
I can't "see" the value of x'length. The only way to explain the loop indexing ptr too high is that something is wrong with the initialization of the range of ptr. I added some debug statements to the function and got this...
at 150.000 ns(1): Note: nxt is d"8" (/IRIG_TB_vhd/). at 150.000 ns(1): Note: ptr is d"1" (/IRIG_TB_vhd/). at 150.000 ns(1): Note: rtn_len is d"2" (/IRIG_TB_vhd/). at 150.000 ns(1): Note: loop i d"1" (/IRIG_TB_vhd/). at 150.000 ns(1): Note: r string "0$" (/IRIG_TB_vhd/). at 150.000 ns(1): Note: ptr old d"1" (/IRIG_TB_vhd/).