Shop OBEX P1 Docs P2 Docs Learn Events
Timing issues within SimpleIDE? — Parallax Forums

Timing issues within SimpleIDE?

RsadeikaRsadeika Posts: 3,837
edited 2012-10-13 05:35 in Propeller 1
I am having some timing issues with PUB wait(time), it runs correctly up to 53, 54 to 60 it falls apart. I am not sure what is causing this to occur.

Ray
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

PUB wait(time)

  waitcnt((80_000_000 * time) + cnt)

Comments

  • jnmljnml Posts: 14
    edited 2012-10-12 05:11
    Rsadeika wrote: »
    I am having some timing issues with PUB wait(time), it runs correctly up to 53, 54 to 60 it falls apart. I am not sure what is causing this to occur.

    54 * 8e7 > 2^32 ;-)

    -j
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-10-12 05:27
    That's interesting, so does anybody have a better PUB for producing a wait period for one minute or more without resorting to using an RTC?

    Ray
  • jnmljnml Posts: 14
    edited 2012-10-12 08:11
    Rsadeika wrote: »
    That's interesting, so does anybody have a better PUB for producing a wait period for one minute or more without resorting to using an RTC?

    Ray

    Totally untested code from top of my cog ;-)
    PUB sleep(seconds)
      repeat seconds
        sleepSec
    
    PRI sleepSec()
      waitcnt(clkfreq+cnt)
    

    HTH

    -j
  • AribaAriba Posts: 2,690
    edited 2012-10-12 20:03
    Or if you need the time more exact:
    PUB sleep(seconds) : time
     time := cnt
     repeat seconds
       time += clkfreq
       waitcnt(time)
    

    This eliminates the little errors you get for the calls of the 1 second delays.

    Basically waitcnt can only handle delays up to 54 seconds (@ 80MHz) because cnt is a 32 bit register. But you can repeat shorter delays as much as you like.

    Andy
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-10-13 02:06
    Thanks guys, this is a great practical lesson learned on my part. It never really dawned on me to really look at my function, or any of my functions, from the stand point of, what the limitations of a 32 bit register are. This may slow down my programming style, because now I will have to consider the limitations of all my functions. My bad for even thinking that it would be a problem with SimpleIDE, when in fact it is a problem with my not knowing enough about the basic limitations of 32 bit registers. Will have to be very cautious from now on.

    Ray
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-10-13 05:35
    Ray,

    It seems most folks back into the 53 second delay the other way.

    "I set my timer for some <too short> period and my Prop goes to sleep for almost a minute before it wakes up" or they don't wait the minute and just thinks it hangs.

    If they just say hang or long period delay, most of the older forum members ask "is it about a minute?" :0)
Sign In or Register to comment.