> I guess the err is triggered because value 37(in this specific sim) is
> used for the check(?)
No, its triggered because 25 in pos_cnt is more than 3 in this line:
if pos_cnt>3 or pos_cnt<-3 then
err <= '1';
> i fail to understand how clearing the pos_cnt and checking it on the
> same edge of the index
As I said: latency.
You must dig in much deeper in the behaviour of signals in processes!
To say it simple: they do not change their value throughout the process.
They keep their "start values" from the beginning of the process to the
end of the process.
When you assign a new value to a signal them the signal does not change
its value! The new value is just "memorized" until the end of the
process. Then it is assigned to the signal.
So in your specific "problem" it looks like that:
if ENA_I then -- Sim: ENA_I is 1
if dr_I = "01" then -- Sim: dr_I is 01
pos_cnt <= 0; -- kind of magic here: pos_cnt does not change its value as it is a signal!
-- the assinged value is not updated till the end of the process!
err <= '0';
if pos_cnt>3 or pos_cnt<-3 then -- Sim: pos_cnt is still 25 here and throughout the whole process!
err <= '1'; -- obviously we will end up here... :-(
This kind of behaviour is really nice, when you are used to it. But
first you must "get the trick" somehow... ;-)