View Full Version : Computing write/read speed

05-24-2010, 11:45 AM
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)


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,


Phil Pilgrim (PhiPi)
05-24-2010, 11:56 AM
My umath object (attached) might help with the overflow and sign problems.


05-24-2010, 08:31 PM
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

05-24-2010, 09:21 PM
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