- Does it help during simulation/verification?
yes
- Does it ensure that tick_counter stays within range. (not sure, but I guess it should at least warn you during simulation)
With ModelSim you always get "bond error" (severity level -> simulation halted) if an integers/positive/natural goes out of the range.
- What is the point of an tick being integer if it doesn't go negative? Will it still have a sign bit? If you accidentally subtract 1 from 0, will it be -1?
Do you prefer "natural" or "positive" ? Of course, if you can use it: integers is signed, and it's 32 bit range. Positive is unsigned 32bit. If someone needs a huge counter, he/she had better use a sub range of positive.
- If you were worried about undefined reset states, or SEUs doesn't it hide too much to know the possible states?
No because
- everything (even integers) is pre-initialized once declared, signal blablabla := INIT_VALUE;
- counters are integers, everything else is handled with "std_logic_vector" and "unsignend"
- they both propagate X and U status, and you can see and react to mistakes from the simulator
Nothing is hidden, the there is always a starting value for counters! It's the fist thing I check when I simulate.
Aren't you relying on the smarts of the tools deduce the allowable range, dropping bits as needed:
well, I wrote a simple VHDL parser as "analyzer", and it was relatively easy to read a integer signal, look at its range, and deduce how many bits it takes
x=get_abs_max(range_min, range_max) ==> n_bit=get_log2(x);
ModelSim is even smarter than my simple tool by several and several orders of magnitude, and so it's ISE.
my code looks like this, anyway
if rising_edge(in_clock) then
if state = idle then
else
if tick_counter=tick then
tick_counter<=0;
else
tick_counter <= tick_counter+1;
end if;
end if;
constant tick : integer := clk_freq/baudrate;
signal tick_counter : integer range 0 to tick;
[..]
if tick_counter=tick then
It's a reload-to-zero trick, there is no
'high because ISE is not able to understand it, thus this solution works for both ModelSim and ISE.
In my experience, it's better using a "compare_equal" rather than "compare_less_than"