Shop OBEX P1 Docs P2 Docs Learn Events
Waitcnt function not working or waiting random times — Parallax Forums

Waitcnt function not working or waiting random times

landon1974landon1974 Posts: 1
edited 2012-06-29 10:05 in Propeller 1
I am new to the propellor and the forums. I have a snippet of code that should move through a number of servo positions waiting about 1 second between moves. The issue I am seeing is that the waitcnt function isnt waiting the correct amount of time. The program will cycle through the positions correctly, but the wait time between positions is random at best. <BR><BR>I have attached the code for reference. Any help would be appreciated.

Comments

  • pik33pik33 Posts: 2,397
    edited 2012-06-29 08:44
    Waitcnt waits until cnt reaches its argument. So, instead of

      waitcnt(clkfreq)
    

    use
      waitcnt(cnt+clkfreq)
    

    This is still not the best solution because you have some code between waitcnt's
    a:=cnt
    repeat
      a:=a+clkfreq
     {do something}
      waitcnt(a)
    

    Now this {something} will be done every one second
  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-29 08:58
    pik33's 2nd suggestion is indeed a way to get very precise intervals of one second, but it's rarely used for intervals that long. The 1st suggestion is what's usually used. The difference between the two will be on the order of tens of microseconds. The 2nd suggestion is more commonly used for intervals more like milliseconds or hundreds of microseconds.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-06-29 10:05
    For those that previously learned to code timers in Basic or just loops in Assembler - Waitcnt may seem very odd. It is likely THE MOST DIFFERENT concept about using a parallel device.

    The simplicity of it is that there is a central counter that one refers to for nearly all their counting needs. It allows central coordination of all the COGs.

    That last piece of code the three above alternatives is intended to eliminate any jitter or creeping inacuracies.
Sign In or Register to comment.