Shop OBEX P1 Docs P2 Docs Learn Events
timing questions — Parallax Forums

timing questions

mynet43mynet43 Posts: 644
edited 2011-11-22 19:04 in Propeller 1
I have two questions regarding timing. One easy and one not so...

1. Does anyone know the time it takes a propeller to start up after the power is applied? I'm sure I can look this up somewhere but it's not obvious.

2. Does anyone have assembly code that approximates the assembly waitcnt command (not the spin waitcnt)? I need this so I can be doing other stuff while it's waiting. It's tricky to do without encountering the 32 bit overflow problem. It doesn't need to be quite as precise but it should be accurate and reliable.

Thank you for your help.

Jim

Comments

  • pjvpjv Posts: 1,903
    edited 2011-11-20 21:36
    Hello Jim;

    If you search in the Parallax contests site, you should be able to find my entry which is a co-operative assembler RTOS letting one cog do more than one thing "simultaneously". There are examples as well as commented code. You should be able to get timing working to 1 usec granularity if I recall correctly without looking it up. The actual precision will be dependent on the level of "busyness" in the cog.

    And as to how long a Prop takes to boot.... I think the manual states a 75-ish millisecond power-up timer.

    Hope that helps.

    Cheers,

    Peter (pjv)
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-11-21 08:12
    Most of the serial drivers do a non-wait "waitcnt". Here's a snippet of code from FullDuplexSerial.
    :wait                   jmpret  txcode,rxcode         'run a chunk of receive code, then return
    
                            mov     t1,txcnt              'check if bit transmit period done
                            sub     t1,cnt
                            cmps    t1,#0           wc
            if_nc           jmp     #:wait
    
    txcnt contains the target cycle count. The loop falls through when (txcnt - cnt) is less than zero. Otherwise, it does a jmpret to execute another portion of the driver.
  • mynet43mynet43 Posts: 644
    edited 2011-11-21 08:46
    Hi Dave,

    Thanks for the snippet. It looks like the trick is using the cmps, which treats it as a signed compare.
  • mynet43mynet43 Posts: 644
    edited 2011-11-21 08:56
    Peter,

    Do you have a link to your code? I'm very interested. I'm not sure where to look for the contests site.

    Thanks for the info.

    Jim
  • AribaAriba Posts: 2,690
    edited 2011-11-21 10:40
    mynet43 wrote: »
    Hi Dave,

    Thanks for the snippet. It looks like the trick is using the cmps, which treats it as a signed compare.

    The real trick is the sub t1,cnt
    The cmps checks only if the result of the subtract is positive (value not reached) or negative (value reached or passed).
    If you subtract two 32bit numbers and the result is again a 32bit number you have no problems with overflow up to the half of the number range (31bit here). So this trick works up to ~27 seconds timing intervals @80MHz.

    To 1): The booting time is ~1.6 seconds according the datasheet on page 30.

    Andy
  • mynet43mynet43 Posts: 644
    edited 2011-11-21 12:12
    Andy,

    Thanks for the correction of the startup time.

    I'm still having trouble understanding the waitcnt code. Sometimes I'm pretty dense :)

    If the sub t1,cnt is determining the result, then why not use a wc on the sub command and skip the cmps command? I'm sure I'm missing something.

    Thanks for your help.

    Jim
  • AribaAriba Posts: 2,690
    edited 2011-11-21 12:24
    mynet43 wrote: »
    If the sub t1,cnt is determining the result, then why not use a wc on the sub command and skip the cmps command?

    You would need a sub command which returns a Sign-Flag in C. But that not exists. sub returns the overflow for unsigned numbers and subs the overflow for signed numbers.
    The trick here is exactly to ignore the overflows and look just at the result if it is positive or negative.

    Andy
  • mynet43mynet43 Posts: 644
    edited 2011-11-21 12:36
    Andy,

    OK, thanks, that helps.

    J
  • pjvpjv Posts: 1,903
    edited 2011-11-22 12:31
    Hi Jim;

    I believe the link is http://www.parallax.com/Resources/ApplicationsContests/Contests/200910PropellerContest/PropRTOS/tabid/852/Default.aspx

    There is a considerably more advanced RTOS that I have written, but because of the MIT requirements for publishing in the OBEX, that version remains private. If a non-MIT license publishing area existed on the Parallax site, then I would publish it there for non-commercial use.

    Cheers,

    Peter (pjv)
  • mynet43mynet43 Posts: 644
    edited 2011-11-22 19:04
    Peter,

    Thank you for sharing your RTOS code with me. I appreciate it.

    I've looked over your code and I think I understand how to use it and how it works. I really like the compactness of your code and the way you use the jmpret command to suspend code execution and return to the scheduler.

    I would be very interested in seeing your more-advanced version, to see what extensions you've added. If you're willing to share it with me, you can email it to me under separate cover.

    Thanks again,

    Jim
Sign In or Register to comment.