Is this legal?

J

Jan Decaluwe

Valentin said:
May be "stop bit" expression is misleadind, simulator stops in different
place.

if SampleCnt = 7 then
BitPos <= BitPos + 1; -- ModelSim stops here
if BitPos = 10 then -- STOP condition (UART stop bit)
BitPos <= 0;
.. -- check stop bit is '1'


I'm writing here just because when Sample = 7 and BitPos = 10 ModelSim shows
me message "Value 11 is out of range 0 to 10" and does not proceed. I
understand which signals I have at which cycles. There is no condition where
BitPos = 11; my logic prevents this. Please, tell me where is my (0..10)
constraint violated? I expect simulator to warn me only when things go wrong
due to inconsistency or a hole in my logic. I don't not want it to stall
when everithing is going as planed.

Interesting ... when I went through the exercise of implementing my Python-based
MyHDL simulator (loosely modeled after VHDL) I encountered the same issues. Here's
my reasoning.

When checking signal bounds, there are 2 options:

1. checking bounds at the actual update, when all processes have stalled.
This is "obviously" the correct thing to do.
2. checking bounds at each signal assignment. This may be pessimistic,
as the example shows.

Initially, I implemented (1), of course. However, later I reverted to (2).
Why? Because (1) didn't behave as a practical run-time check to my taste.
At update time, execution has moved far beyond the offending line, and the
context has changed. I just got a traceback from the simulation kernel about
a signal bound error - but without any direct clue, such as the offending
line, about what caused it.

In contrast, with (2), simulation stops exactly at the line that
(potentially) causes the problem, with the exact context to examine.
99% of the time, the problem will be real, and in the other case,
the code is probably confusing and the workaround will make it clearer.
In this case, I would prefer to put the counter increment in the else
case. I love default assignments, but in this case I don't think they
made the code clearer.

So I think this is a case where "practicality beats purity" as we say
in the Python community.

Regards, Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top