delays with loops

Questions about the BASICtools and MakeItC
Post Reply
Posts: 992
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA

delays with loops

Post by basicchip » Wed Jan 16, 2013 11:34 pm

>from help line
>... what's driving
> me crazy at the moment is trying to get a short (1-2usec)
> delay to give the open drain clock lines enough rise
> time...
> trying something like this: void dly1() { for (x=0;
> x<100; x++) z++; } where x and z are ints
> can you explain why the compiler gives me no delay for
> this? doesn't seem to matter what the loop limit is, it
> only takes 200 nsec!

Most likely this is being optimized out by the compiler, it probably sees that z
is never used. You can verify that by looking at the ASM listing (under the
edit options)

To change that, I'd suggest making it a global variable.

Actually you could also use the TIMER to get a 1-3 uS delay, just wait for 2

Most likely other ways to force it (maybe volatile), I'd have to open a C

While you could turn off optimization, I try not to do that.

Post Reply