Hi Joep,

On 05/02/10 10:18 pm, Joep Suijs wrote:

2010/5/2 Rob Hamerling<[email protected]>:

Or am I overlooking something?
Indeed you are, but it surprised me at the time and is well-hidden due
to a lack of comment...
At low clock rates, the constant can become negative and (at least at
the time) there was an issue with signed compares. So this is the way
to handle these.

I'm afraid I don't follow you (even with the additional comment).
The essential part of the procedure for delay_1ms:

const _one_ms_delay = 1000 - ((14 * instruction_time) / 100)
for n loop
   if (_one_ms_delay <= 1000) then ; check if delay is not negative
      _usec_delay(_one_ms_delay)

Constant '_one_ms_delay' is unqualified, meaning it is universal, thus a signed 32 bits integer. With instruction time zero, it will have the value 1000, with every other (positive!) instruction time it will become lower than 1000. So the condition is always true (also when negative, e.g. with an oscillator freq. of 32 KHz it will get the value approx. -700).
To prevent a negative value I would think it should be:
   if (_one_ms_delay > 0) then

Even when there was an issue with the compiler with signed compares (at the time) I don't think it was a good condition check.


Even when the 'if' is needed a delay of 1 usec is neglectable compared to
the number of instructions in the rest of the procedure, which would be
another reason to ditch the else branch.

I don't recall all details, but the us delay was put in to get *some*
delay. If there was no delay, the loop is not executed at all and
delay_1ms(1000) will return almost immediately.

Aha, true, I forgot that the 'if' is a constant expression!

Regards, Rob.

--
Rob Hamerling, Vianen, NL (http://www.robh.nl/)

--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to