Shop OBEX P1 Docs P2 Docs Learn Events
Some question for bs2 — Parallax Forums

Some question for bs2

chinese boychinese boy Posts: 2
edited 2006-09-29 18:52 in BASIC Stamp
How can·we know the time of every BS2' command step?
BS2 send a square wave out,at a same time·can it·do any other thing?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-09-28 13:25
    The BS2 is a "single thread" platform. When it's doing a "PULSOUT" it's not 'listening' on a serial port.
    The BS2 consists of several 'family' members, each of which has a different IPS (InstructionsPerSecond) speed. Typically the BS2 'plain' does about 300 uSec per instruction.

    You CAN set a pin's output state, and it will hold that state while other things happen. So, you COULD generate a square wave with:
    MAIN:
    HIGH OutPin
    LOW OutPin
    GOTO MAIN

    in which case, you COULD do something between the 'high' and 'low' set statements. That would give you a square wave with about a 1 mSec period though -- 1000 Hz.
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-09-28 23:21
    This is how I've done it:
    Take the code you want to time and set up a "FOR...NEXT" loop for 100 iterations.
    Setup an LED to light up before the "FOR" and shut off after the "NEXT"
    Use a stopwatch or a watch with a Lap timer and divide the result by 100.
    use more iterations for higher resolutions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-09-29 04:24
    TechnoRobbo,

    Your technique is sort of how it's done with a scope, only you want a command that is symmetrical so you can determine an accurate time.


    1) Initialize a pin as an output LOW
    2) TOGGLE that pin twice (now you have a start pulse)
    3) Perform your task that you want to time
    4) TOGGLE that pin twice again (now you have a end pulse)


    The first time you run this you want to omit #3 so you can determine how "long" the TOGGLE command itself takes. Measure the time from rising edge to rising edge.
    This value will be the "Constant" value you will subtract from future readings with step #3 implemented.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • chinese boychinese boy Posts: 2
    edited 2006-09-29 18:35
    Thank you for your help!
    If I want to send a square wave with a exact cycle,how can I do?
    And the cycle is as short as possible.

    low pin
    main:
    pulsot pin,cycle+
    goto main

    and cycle0 is?
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-09-29 18:52
    Try this:

    low pin
    Main:
    toggle pin
    {Test timing here}
    goto main

    This way you can still monitor the time it takes for a specific function/command to execute by measuring the time from rising edge to rising edge. (<--...or falling to falling as long as you are consistent)
    Run this first without {Test timing here} to obtain your "constant value". Remember to divide your results by 2 to get the correct reading after you subtract your "constant value" from the
    result with {Test timing here} in place.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.