Shop OBEX P1 Docs P2 Docs Learn Events
Gernal timing question: Spin vs assembly execution speed — Parallax Forums

Gernal timing question: Spin vs assembly execution speed

bkrazbkraz Posts: 2
edited 2007-04-28 02:26 in Propeller 1
Hello everybody.· I am just getting started with the Propeller and have a question that hopefully someone will find very easy to answer.· I am running this program:

CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· Pin = 1··············································································
················································································
PUB Start
· dira[noparse][[/noparse]Pin]~~·································································· ' Make Pin Output···
· repeat··············································································
··· outa[noparse][[/noparse]Pin]~····························································· ' Clear I/O Pin
··· outa[noparse][[/noparse]Pin]~~·································································· ' Set I/O Pin


With an oscilloscope on Pin 1, I see the pulse time is about 10us (microseconds) on and 10us off.· This is pretty slow compared·to the 80MHz system clock.· Where are all those thousands of clock cycles going for each pulse?

When I run the following assembly program I get pulse widths·down into the nanoseconds!· Is Spin really THAT much slower than assembly?· Thanks for any suggestions you might have.· -Ben

con
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
pub Toggle_Main
· cognew (@Toggle, 0)
dat
······················· org······ 0
Toggle
············· mov···· dira,·· Pin··············· 'Set Pin to output
············· mov···· Time,·· cnt··············· 'Place the value of cnt into Time
············· add···· Time,·· #9················ 'Add 9 to time
:loop
·······
············· xor···· outa,·· Pin··············· 'Toggle Pin
············· xor···· outa,·· Pin··············· 'Toggle Pin
············· jmp···· #:loop
Pin···· long··········· |< 1
Time··················· res 1
·

Comments

  • parskoparsko Posts: 501
    edited 2007-04-27 08:33
    As a rule of thumb, Assembly is about 200 times faster, due to the compilation. Basically, SPIN is compiled assembly commands.

    Your spin routine should be doubled in speed if you use the "!" command, instead of the two "outa[noparse][[/noparse]pin]" commands. So, try replacing your two "outa's" with one "!outa[noparse][[/noparse]pin]" in the loop. Remember to set the pin initially...

    -Parsko
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-04-27 08:43
    Apologies but from the typo in the thread title I thought you were asking about something else:

    http://en.wikipedia.org/wiki/Gurning

    Although the spelling is different again [noparse]:)[/noparse]

    attachment.php?attachmentid=46885
    349 x 247 - 34K
  • simonlsimonl Posts: 866
    edited 2007-04-27 09:02
    Graham, you're in a strange mood today; you on suffin'? LOL

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon

    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif

    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
  • bkrazbkraz Posts: 2
    edited 2007-04-27 17:17
    Thanks very much for your responses!· This forum is a great resource, and I plan to contribute myself after I've become a little more familiar with the Propeller.

    In the past, I've used the BasicX BX24 in MANY projects, and have occasionally used Atmel chips running assembly code.· The Propeller seems like a completely new (and better) way of doing things, but it appears the vast majority of coding must be done in asm to take advantage of the chip's speed.

    Also, I like the creative way of pointing out my typo.· I truly had no idea what to expect when I saw that picture load!

    Thanks again!· -Ben



    ·
  • rokickirokicki Posts: 1,000
    edited 2007-04-27 17:20
    On the contrary, for most things only the really time critical stuff needs to be done in assembly.
    For instance, my FAT16 secure digital support has almost all the code (the file system) done in
    spin, and only the very low-level stuff that actually moves blocks onto and off the card is in
    assembly.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-28 02:26
    Most stuff can be done in Spin with very little effect on overall execution speed. For example, Spin can do "bit-banged" serial I/O up to about 19.2KBaud. The two counters that are part of each cog can be used for frequency generation from Spin or for digital to analog conversion from Spin. Assembly is important when raw speed is important or tight timing control (finer than maybe 20-50us) is needed. Using the system clock and WAITCNT, you can time Spin code with a 12.5ns granularity, but there may be some hard to predict delays from the WAITCNT until the actual action you want is executed.
Sign In or Register to comment.