Shop OBEX P1 Docs P2 Docs Learn Events
Parallel loops ? — Parallax Forums

Parallel loops ?

ArchiverArchiver Posts: 46,084
edited 2002-11-04 21:49 in General Discussion
Hi again,
Specifically, I want three TTL outputs (using the HIGH and LOW
commands or TOGGLE, that do this...
one at 10ms square wave
one at 20ms square wave
one at 500ms square wave

In the only program I'm "good" at, LabVIEW, I'd do parallel loops, but
I'm not sure how to do this in pbasic.

This list is great, thanks in advance.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-04 21:49
    Here's a 3-line program that puts out square waves with periods of
    about 10, 20 and 500 milliseconds on p0,p1 and p2 respectively. The
    "about" can be improved if you play with the timing, or if you have
    an external period reference. The calculations take time, which
    depends on which Stamp you are using.

    x var word
    dirA=$f ' port A is outputs
    loops:
    outA=(x/50<<2)|(X//4/2<<1)|(X//2)
    x=x+1//100 ' takes ~500ms to count 0 to 99
    pause 4 ' the above stuff takes ~1 millisecond, 5 total.
    goto loops

    the statement with "outA=" is what sets the output bits. For
    example, each ~5 milliseconds, x advances by one count, so x//2
    alternates zero and one, and that is transferred to p0. "x/50" is
    zero when x is less than 50 and one when x is greater than 50, and
    that is shifted into the position to control output bit p2.

    -- Tracy Allen



    >Hi again,
    >Specifically, I want three TTL outputs (using the HIGH and LOW
    >commands or TOGGLE, that do this...
    >one at 10ms square wave
    >one at 20ms square wave
    >one at 500ms square wave
    >
    >In the only program I'm "good" at, LabVIEW, I'd do parallel loops, but
    >I'm not sure how to do this in pbasic.
    >
    >This list is great, thanks in advance.
Sign In or Register to comment.