Code Execution Time
JoeFL
Posts: 10
Hi, I'm fairly new to Spin and the Prop. I was identifying some executions times in my program and have come
across some code which has varying execution times and I'm wondering why that is?
I've attached the spn file for ease of use. One can use viewport and watch the variable MT1D change every 2 seconds
Thanks for you time
Joe
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 'use standard 5MHz clock
OBJ 'includ ViewPort objects:
vp : "Conduit" 'transfers data_ to/from PC
Var
long MT_St,MT,MT1,TBP,data_,MT1D
PUB Detect_Rate
vp.config(string("var:TBP,data_,MT1D"))
vp.share(@TBP,@MT1D) 'share variables
data_ := 18 'sets product delivery rate
TBP := (3600*80_000) / data_ 'TBP Time Between Product in clock tics
' 80_000_000 tics/sec
repeat
if MT_St == 0
MT := cnt 'MT Mark Time, 1st time thru loop
MT_St := 1
if MT_St
MT1 := cnt - MT 'keep looking at MT1
if MT1 => TBP
MT_St := 0
MT1D := MT1 - TBP 'This difference in Time seems to vary quite a bit
waitcnt(2*clkfreq + cnt) 'I don't know why?
data_++
TBP := (3600*80_000) / data_
Time_Calc.spin
across some code which has varying execution times and I'm wondering why that is?
I've attached the spn file for ease of use. One can use viewport and watch the variable MT1D change every 2 seconds
Thanks for you time
Joe
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 'use standard 5MHz clock
OBJ 'includ ViewPort objects:
vp : "Conduit" 'transfers data_ to/from PC
Var
long MT_St,MT,MT1,TBP,data_,MT1D
PUB Detect_Rate
vp.config(string("var:TBP,data_,MT1D"))
vp.share(@TBP,@MT1D) 'share variables
data_ := 18 'sets product delivery rate
TBP := (3600*80_000) / data_ 'TBP Time Between Product in clock tics
' 80_000_000 tics/sec
repeat
if MT_St == 0
MT := cnt 'MT Mark Time, 1st time thru loop
MT_St := 1
if MT_St
MT1 := cnt - MT 'keep looking at MT1
if MT1 => TBP
MT_St := 0
MT1D := MT1 - TBP 'This difference in Time seems to vary quite a bit
waitcnt(2*clkfreq + cnt) 'I don't know why?
data_++
TBP := (3600*80_000) / data_
Time_Calc.spin
Comments
Note that execution time for the same sorts of operations will vary somewhat depending on where the operands come from or, if constants, what their value is. Access to variables takes different amounts of storage and time depending on whether the data is in global variables or local variables or involves subscripting. Some constant values like 0, 1, -1, and some powers of two are encoded compactly and take different amounts of storage and execution time.
By the way, don't use cut and paste on code in postings without using [ code ] tags as described here:
I did try using my loop code without the waitcnt
I set up a breakpoint in my debugger at the end of the loop
I looked at the Time Difference TMD1 variable
Then manually changed my data_ var, compiled and restarted with breakpoint
I looked at the Time Difference TMD1 variable
The code execution time pretty much varied the same times as with the waitcnt in the code
The variation was from up to 12_000 clock tics, far within the time resolution of the required application
Its been many moons since I did any assembly programming, but I sorta understand your point
about division not having a finite execution time.
Thanks Mike
When I run this with the WAITCNT and the following two lines removed, I get a display of 2048 that stays fixed. When I run this with the WAITCNT and the other two lines, I get a display that varies from somewhat under 1000 to around 2000. I think this is due to the WAITCNT which causes a 2 second delay that may finish sometime after CNT has passed the TBP point. I think that accounts for the variation. Because data_ is being incremented every few seconds, I expect the displayed value will drift as TBP changes.