Shop OBEX P1 Docs P2 Docs Learn Events
Computing write/read speed — Parallax Forums

Computing write/read speed

KyeKye Posts: 2,200
edited 2010-05-24 13:21 in Propeller 1
I'm trying to do some integer only math using spin and I'm encountering some overflow problems.

Basically I have the cnt difference from the start of writing to a file and from the end of writing to a file. However,·the value goes above POSX.

What I want to do (as if I had floating point) is:

timeDelta = ((stopCNT - startCNT) / clkfreq)

and

bytesPerSecond = (131072 / timeDelta)

---

The problem with doing this is that if the value is rather low with integer only math I need to scale it up. Buf if I do that every time then if the value is to high I will have an overflow.

Then I also have the problem of SPIN's signed math, if the value is above POSX then its hard to do math in the first place on the value.

...

So what can I do?

Thanks for your help,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-24 03:56
    My umath object (attached) might help with the overflow and sign problems.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-05-24 12:31
    You could use a LOGIC ALWAYS counter and use that as your cycle difference (0..N, counter starts at 0). Provided no action exceeds an overflow (e.g. 53.69sec @80MHz) or - even stricter - goes into signed land (26.8sec) that should be sufficient.

    Post Edited (kuroneko) : 5/24/2010 1:34:24 PM GMT
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-24 13:21
    Keep in mind that division is signed and, based on the value on CNT when you grab it, your calculated delta could be a negative value. I just did a blurb about timing tests in my last N&V column with something like this:

    t0 = cnt
    ' code to test here
    delta := ||(cnt - t0)
    


    As Marko indicates, the is good for durations up to CLKFREQ/2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.