PDA

View Full Version : number of clock cycles for a spin instruction



Talheaern
06-05-2010, 05:27 AM
I am using an ultrasonic sensor that requires I wait 65mS for a result.

Instead of using a waitcnt for that time I would like to run some code written in spin.

The problem is how much code will cover 65mS? And if I do not have enough code
what is a good guess how long it did take?

If I understand the Propeller data sheet assembly instructions take 4-7 clock cycles.

I know it will vary by spin instruction, but what is a good number to start with?

Bill Henning
06-05-2010, 05:33 AM
Spin byte codes are interpreted, and if I correctly recall, take 60us to 200us to execute.


Talheaern said...
I am using an ultrasonic sensor that requires I wait 65mS for a result.

Instead of using a waitcnt for that time I would like to run some code written in spin.

The problem is how much code will cover 65mS? And if I do not have enough code
what is a good guess how long it did take?

If I understand the Propeller data sheet assembly instructions take 4-7 clock cycles.

I know it will vary by spin instruction, but what is a good number to start with?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com (http://www.mikronauts.com) E-mail: mikronauts _at_ gmail _dot_ com
My products: Morpheus (http://mikronauts.com/products/morpheus/) / Mem+ (http://mikronauts.com/products/morpheus/memplus/) / PropCade (http://forums.parallax.com/showthread.php?p=894725) / FlexMem (http://forums.parallax.com/showthread.php?p=894853) / VMCOG (http://forums.parallax.com/showthread.php?p=878382) / Propteus (http://mikronauts.com/products/propteus/) / Proteus (http://mikronauts.com/products/proteus/) / SerPlug (http://mikronauts.com/products/serplug/)
and 6.250MHz Crystals to run Propellers at 100MHz (http://mikronauts.com/products/mikronauts-625mhz-crystal/) & 5.0" OEM TFT VGA LCD modules (http://forums.parallax.com/showthread.php?p=852195)
Las (http://mikronauts.com/software-products/largos/) - Large model assembler Largos (http://mikronauts.com/software-products/largos/) - upcoming nano operating system

BR
06-05-2010, 05:43 AM
Depending on the device you're using and what's required, you might be able to use the counters to perform the measurement task similar to what is done in this object:
http://obex.parallax.com/objects/511/

Or, at the very least, you could set a counter in free-running mode and put checks in your spin code so you could continue to execute spin code with periodic tests of the counter value against a known threshold needed for 65 ms to elapse. When counter value exceeds, threshold, jump to measurement routine...

BR

Post Edited (BR) : 6/4/2010 10:49:45 PM GMT

Timmoore
06-05-2010, 05:46 AM
Just save cnt when you start then periodically compare cnt against the saved value+65ms and get the result it more than 65ms has gone by.
Heres an example driver for a different sensor, you call GetPressure at intervals, if you dont specific wait, it returns false if not enough time has gone by, otherwise it returns true and the sensor reading. If you set wait to true if waits the remaining time needed.

Post Edited (Timmoore) : 6/4/2010 10:52:39 PM GMT

Talheaern
06-05-2010, 06:30 AM
Thanks guys these are all good ideas!

Mike Green
06-05-2010, 06:41 AM
Part of the problem figuring this out is that Spin source is compiled into Spin bytecode instructions each of which can take a different amount of time to be interpreted. It's possible to look at the code produced by the two 3rd-party Spin compilers, BST and HomeSpun, which will both produce listings. The Spin interpreter source is available and you can do instruction counting for the bytecodes you're interested in, but you'll have to do it yourself. No one has done the work and shared their findings. As you can imagine, it's very tedious. Bill Henning mentioned a range of around 60us to 200us with an 80MHz system clock. That's the best that we have.