How to convert CNT ticks to milliseconds?
Akkarin
Posts: 43
Hi there,
I use CNT to determine how long it takes to execute some commands. At the end I get around 500_000 ticks, which corresponds to 6.25ms.
How can I do this conversion in Spin?
At the moment I'm using "Float32Full" (fm in the code below) and "FloatToString" (fs in the code below) to get a useful result but I think this is quite inconvenient and also it doesn't look pretty in the code
I'm sure this can be done much simpler. I bet it's so simple I'll be embarrased that I even asked this ....
I use CNT to determine how long it takes to execute some commands. At the end I get around 500_000 ticks, which corresponds to 6.25ms.
How can I do this conversion in Spin?
At the moment I'm using "Float32Full" (fm in the code below) and "FloatToString" (fs in the code below) to get a useful result but I think this is quite inconvenient and also it doesn't look pretty in the code
stopWatch += cnt-544 msec := fm.FDiv(fm.Ffloat(stopWatch),fm.Ffloat(clkfreq)) pst.str(string("Time elapsed [ticks]: ")) pst.dec(stopWatch) PST.NewLine pst.str(string("Time elapsed [msec]: ")) pst.str(fs.FloatToString(fm.Fmul(msec,fm.FFloat(1000)))) pst.Home
I'm sure this can be done much simpler. I bet it's so simple I'll be embarrased that I even asked this ....
Comments
Assuming you want similar accuracy - this is a common trick for avoiding the overhead of floats.
Thanks Mark_T
Here's a more generic method for displaying "pseudo-real" numbers.
Here's Mark's code using the DecPoint method.
Mark's original code wouldn't display all the numbers correctly. If "10.01" were to be displayed, it would show up "10.1".