Shop OBEX P1 Docs P2 Docs Learn Events
Cnt Rollover — Parallax Forums

Cnt Rollover

James NewmanJames Newman Posts: 133
edited 2008-02-19 03:09 in Propeller 1
There have been a few discussions on this, but I have a hard time finding what's decided. Also, it doesn't seem to be mentioned in the Tricks and Traps.
What's the best way to handle cnt rollover (in asm) when trying to check a delay.

I have 3 variables, ie: start, delay, and cnt.

Did we ever decide on the best way of checking if cnt > start+delay?

(Edit)
I did make a little table with the possible correct responses, btw.
1) Cnt < start < start+delay -> Delay time exceeded
2) Cnt < start+delay < start -> Still in Delay
3) start < start+delay < Cnt -> Delay time exceeded
4) start < Cnt < start+delay -> Still in Delay
5) start+delay < Cnt < start -> Delay time exceeded
6) start+delay < start < Cnt -> Still in Delay

In 3 and 4 no values have rolled over.
In 1, Cnt has rolled over
In 2, Cnt has rolled over, but is less than start+delay, which has also rolled over
In 5, Cnt has rolled over, and has passed start+delay, which has also rolled over
In 6, start+delay has rolled over, but Cnt has not yet.

Post Edited (James Newman) : 2/18/2008 5:14:15 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-18 05:10
    I always do "cnt - start > delay". That allows you to ignore signed / unsigned arithmetic for delays up to about 25 seconds (for an 80MHz system clock).
  • James NewmanJames Newman Posts: 133
    edited 2008-02-18 05:14
    Ok, now in asm, do you use signed sub and cmp or unsigned? Or does it matter? I should be able think about it, but the whole thing is kinda hurting my head... [noparse]:([/noparse]
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-18 05:44
    Again, for times less than about 25 seconds with an 80 MHz system clock, it doesn't matter whether you use signed or unsigned instructions. For times from about 25 seconds to about 50 seconds, you have to use unsigned compare / subtract instructions.
  • James NewmanJames Newman Posts: 133
    edited 2008-02-18 05:47
    ahhh I see. I need to study that a bit more to wrap my head around it, but for the moment, I'm just going to impliment where I need it. Thanks alot. Btw, why isn't this in the prop tricks and traps document?
  • hippyhippy Posts: 1,981
    edited 2008-02-18 09:58
    @ James : I'm guessing no one saw it as a trick or trap or did not think it was worthwhile adding there.

    I'm sure you will therefore update that thread when you have got this working in your own project smile.gif

    There's also the Propeller Wiki where people are welcome to share their knowledge and experiences - propeller.wikispaces.com
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-18 21:03
    (a) Mike's formula is the only one, used by EVERYBODY
    (b) As Hippy says.
    (c) There is no difference between signed or unsigned ADD and SUB other than wrt their flag setting, which however is more complex than you might think in the beginning...
    (d) It is exactly as Mike said, but the kind of SUB does not matter. However in PASM you have ALWAYS to decide whether signed or unsigned CMP is appropriate, although unsigned CMP is needed more often...

    Post Edited (deSilva) : 2/18/2008 10:05:18 PM GMT
  • James NewmanJames Newman Posts: 133
    edited 2008-02-19 01:12
    Ehh I was doing Cnt > Start+Delay ... but that should work too I guess...

    I think it should be listed in the tricks/traps, atleast as a sort of reminder to newbies that cnt does infact rollover, and what effect that will have on any code.

    Thanks all, even though this wasn't my problem -really- it did lead me to my problem... which I should have seen.
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-19 01:46
    James Newman said...
    Ehh I was doing Cnt > Start+Delay ... but that should work too I guess..
    No, it won't and PLEASE think again why it won't!
  • James NewmanJames Newman Posts: 133
    edited 2008-02-19 03:09
    lol, exactly why it should be in the tips and tricks [noparse];)[/noparse]
Sign In or Register to comment.