TIMER wrap around

Questions about the BASICtools and MakeItC
Post Reply
YahooArchive
Posts: 1463
Joined: Fri Oct 19, 2012 5:11 am

TIMER wrap around

Post by YahooArchive » Fri Jan 18, 2013 4:56 pm

>from the help line

It does wrap around, but it is NOT a problem as we are using signed integers.

You can verify this with a simple program (run on the PC emulator)

print hex($90000000 - $70000000)
print hex($10000000 - $f0000000)
run
***DEMO MODE*** loading PC...

ARMbasic[7.41] on the PC Copyright 2008, Coridium Corp.
Executing...
20000000
20000000


... Finished in 0 ms

So you can do

start = TIMER
while TIMER-start < 100
loop

will wait 100 microseconds even through both wrap arounds

>Does TIMER overflow and wrap
> around?
>
> I use a similar function in my HC11 code - reads a 16 bit
> counter -
> prescaled from the CPU clock. It counts from 0 to 2^16-1,
> then wraps back to
> 0.
>
> The problem:
> Say I want a 712 Tick delay (I do)
> I do a "start = TIMER" type assigment
> Later I check if TIMER - start > 712 and do
> something.
>
> However if TIMER was greater than (2^16-1) -
> 712 at the time of the
> "start" assignment the test will either never be true, and
> it'll hang (It
> did!!), or may be true immediately after the 'wrap around'
> depending on how
> the "-" and ">" operators are implemented.
>
> Would TIMER have a similar problem? I guess it would only
> happen every 4000+ secs with a 32 bit counter, but Murphy
> says...



Post Reply