Gernal timing question: Spin vs assembly execution speed
bkraz
Posts: 2
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
·
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
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
http://en.wikipedia.org/wiki/Gurning
Although the spelling is different again [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
BTW: I type as I'm thinking, so please don't take any offense at my writing style
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 ;-)
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
·
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.