Shop OBEX P1 Docs P2 Docs Learn Events
Need help with execution timing / loop control — Parallax Forums

Need help with execution timing / loop control

laser-vectorlaser-vector Posts: 118
edited 2013-03-23 16:53 in Propeller 1
Im in need of a little help,

im trying to control a while loop so that it iterates for some amount of "time" then breaks out and goes on to service other areas of the code.

however i think im having trouble comparing a variable to the "cnt" register and my code shows some unexpected behavior.

I watch the led invert its state every three seconds (or whatever "cycle_time" is set to) but i also notice that every so often the led will invert state very rapidly (as if the while loop doesnt even execute). this only occurs every so often, and im not sure what its synchronous with.
CON
cycle_time = 3  

PUB Main | start_time

dira[23]~~

repeat
  !outa[23] 'Area to be serviced every cycle_time*second (eg: every 3 seconds)
  
  start_time := cnt 'sets the loop entry start time to cnt
  
  repeat while cnt < (start_time+(clkfreq * cycle_time))
    'this part gets serviced very often 
    waitcnt(clkfreq/2 + cnt) '<< example workload for 1/2 seconds!!! 



ive tried using the serial terminal to print out some values:
these are printed just before entering the while loop,

compare = debug.dec(start_time+(clkfreq * cycle_time))

#PROP START>>>
cnt = -748151015 compare = -448184471
cnt = -445589159 compare = -145622615
cnt = -143026983 compare = 156939561
cnt = 159420761 compare = 459387305
cnt = 461753913 compare = 761720457
cnt = 764087385 compare = 1064053929
cnt = 1066535609 compare = 1366502153
cnt = 1369097177 compare = 1669063721
cnt = 1671659033 compare = 1971625577
#THIS IS WHERE THINGS WENT CRAZY>>>
cnt = 1974221017 compare = -2020779735
cnt = 1977527833 compare = -2018125719
cnt = 1982003161 compare = -2013650391


thanks for any insight!!

Comments

Sign In or Register to comment.