Shop OBEX P1 Docs P2 Docs Learn Events
number of clock cycles for a spin instruction — Parallax Forums

number of clock cycles for a spin instruction

TalheaernTalheaern Posts: 7
edited 2010-06-04 23:41 in Propeller 1
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?

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2010-06-04 22:33
    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 E-mail: mikronauts _at_ gmail _dot_ com
    My products: Morpheus / Mem+ / PropCade / FlexMem / VMCOG / Propteus / Proteus / SerPlug
    and 6.250MHz Crystals to run Propellers at 100MHz & 5.0" OEM TFT VGA LCD modules
    Las - Large model assembler Largos - upcoming nano operating system
  • BRBR Posts: 92
    edited 2010-06-04 22:43
    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
  • TimmooreTimmoore Posts: 1,031
    edited 2010-06-04 22:46
    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
  • TalheaernTalheaern Posts: 7
    edited 2010-06-04 23:30
    Thanks guys these are all good ideas!
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-04 23:41
    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.
Sign In or Register to comment.