Shop OBEX P1 Docs P2 Docs Learn Events
Timing in Spin — Parallax Forums

Timing in Spin

CassLanCassLan Posts: 586
edited 2009-06-21 09:37 in Propeller 1
Hi all,

This may seem like a dumb question...that hasn't stopped me before [noparse]:)[/noparse]

Anyway, I'm working on PrEditor, I'm trying to speed it up, I have a routine that takes place with every keystroke, and its just not snappy enough yet

In order to experiment a bit to make it faster I need to know exactly how long its taking.

I've put in the following code:
'' This is the first line of the routine
StartCNT := cnt
 
''This is the last line of the routine
StopCNT := cnt
DiffCNT := StartCNT - StopCNT

Then I display these three long sized variables via Parallax Serial Terminal
I'm thinking the only time this could be incorrect is if the cnt rolls over while the routine is happening...which is why I'm outputting all 3 to the terminal

Currently I have a value of 9,213,008 for the difference between StartCNT and StopCNT
These are clock cycles right?

And since this is happening inside of 1 of 8 cogs, each of these happens at 10Mhz? (5Mhx xtal at x16 PLL)
So thats 921.3 milliseconds?

I know for serious timing stuff PASM should be used, I'm just trying to get a handle on how to clock routines in spin to make sure my improvements are really improvements [noparse];)[/noparse]

Thanks,

Rick

Post Edited (CassLan) : 6/20/2009 8:22:34 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-20 20:25
    First of all, a 5MHz crystal with PLL16X is an 80MHz system clock. Each clock cycle takes 12.5ns. 10,000,000 clock cycles would be 125ms.

    You only need to display the difference StopCNT-StartCNT. For time delays less than around 25 seconds, this will be a correct positive time interval.

    If you want a display in microseconds, display (StopCnt-StartCnt) / (CLKFREQ/1000000).

    If you want a display in milliseconds, display (StopCnt-StartCnt) / (CLKFREQ/1000)
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-20 20:59
    The right diff would be stopCNT - startCNT and not startCNT - stopCNT. Just to point out the difference of Mikes code and yours a bit more clearly.

    To make the result more accurate you can calculate the diff of the two clock-measurements without code in between. This is the offset you can subtract from the diff of your code.

    Post Edited (MagIO2) : 6/20/2009 9:05:44 PM GMT
  • CassLanCassLan Posts: 586
    edited 2009-06-20 21:08
    Thanks guys,

    Yes Its Stop-Start, I had it correct in the program but wrote it incorrectly when posting.

    I understand the total system is running at 80Mhz, I thought that each cog runs independently at 1/8th of that speed
    Is this faulty thinking?

    PS - So far I've got it down by 35%! make that 44%! That multiplication is a killer.

    Rick
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-20 22:35
    Each COG runs at the same speed - 80MHz

    Most instructions need 4 clock-cycles. So the instruction throughput is 1/4th of the system clock which makes 20MIPS per COG.

    Multiplication is bad if you don't have hardware multipy. Remember that multiplication by power of 2 operands (2,4,8,16...) can be done by shifting.

    Post Edited (MagIO2) : 6/20/2009 10:40:27 PM GMT
  • CassLanCassLan Posts: 586
    edited 2009-06-21 09:37
    Got it...I remember a "round robin" action going from cog to cog...that must be for the hub memory, I thought it was for cog execution.

    Rick
Sign In or Register to comment.