Shop OBEX P1 Docs P2 Docs Learn Events
Simple LED problem — Parallax Forums

Simple LED problem

GPeytonGPeyton Posts: 3
edited 2008-11-14 13:03 in BASIC Stamp
Hi there,

As I was going through the "Robotics with Boe-Bot" manual, I came across a small problem with pulsing LED's. Using the following given code, I can't the 2 LED's I'm using (connected to pins 12 and 13) to pulse simultaneously.

DEBUG "Program running!"

DO
  PULSOUT 13, 65000
  PULSOUT 12, 65000
  PAUSE 2000
LOOP



1 Pulses just before the other, for some reason...slightly out of sync. How can I fix this problem?

Also, how to you get it to stop looping or to only loop for a certain amount of time? Even if I turn the power off then back on, it carries on looping.

Thanks [noparse]:)[/noparse]

Post Edited (GPeyton) : 11/13/2008 4:37:40 PM GMT

Comments

  • davejamesdavejames Posts: 4,047
    edited 2008-11-13 16:42
    G,

    I'm going to make an educated guess here and say that your non-synchronous situation is caused by the fact·that the code is serial, meaning, the first PULSEOUT is started then the next.· This will cause one LED to come on before the other making the whole run of both PULSEOUT commands be out-of-sync.

    Correcting this?· Again, educated guess...I'd use the feature of the BasicStamp that allows setting groups of pins as either input or output (in this case set them as output) and then the two pins would be driven in parallel.

    Check the BasicStamp programming/syntax manual chapter 4 right around page 82 for more info.

    Regards,

    DJ
  • GPeytonGPeyton Posts: 3
    edited 2008-11-13 17:04
    Hi DJ,

    I had a look at the manual, and found something relating to what you said, but am totally lost in all the jargon (being about a 2 day old beginner!).

    Sorry to be so slow! blush.gif What do I do?

    Thanks again
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-11-13 17:35
    dir12=1
    dir13=1
    DO
      outD = %0011   ' four bits on p12, p13, p14 and p15 are set to binary %0011, but only p12 and p13 are outputs.
      PAUSE 65
      outD = %0000   ' back to zero
      PAUSE 2000
    LOOP
    



    This will blink both LEDs simultaneously and for a duration of about 65 milliseconds. Commands in PBASIC are always executed sequentially, as in your two PULSOUT commands. The predefined variables dir and out (see the manual for all the variations) let you set the direction and HIGH/LOW state of pins simultaneously. In the above, the pins p12 and p13 are made outputs, and then the outD statement is making them high and low. The % notation means binary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • davejamesdavejames Posts: 4,047
    edited 2008-11-13 17:39
    G,

    Exactly what Mr. Allen has said.

    DJ
  • SRLMSRLM Posts: 5,045
    edited 2008-11-13 17:41
    What you were probably thinking with the pulsout commands is that it would begin executing one, then toss that into the (fictional) "stuff to do while I move on bin". Unfortunately, it doesn't work that way. The entire program execution waits for each line to be completed. Since you have 65000 in the pulsout, it waits for 130,000,000 microseconds before moving on to the next command. All commands in PBASIC are like this (at least all the most common ones for sure...), so you'll want to drop the multi tasking thought process and try procedural programming.
  • GPeytonGPeyton Posts: 3
    edited 2008-11-14 09:58
    Thanks very much for the helpful replies. I tried the given code, and it worked.

    Just one more question: Why do HIGH and LOW commands produce a synchronised result, but PULSE commands produce a non-synchronised result? This is what I found experimentally.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-14 13:03
    Because "high" and "low" command can change the output states of two pins simultaneously. Where a "PULSOUT" affects only a single pin.

    That, and the BS2 is a "Single tasking processor", so the first PULSOUT has to complete before the second PULSOUT can begin. This might not be obvious from the manual, but it is true.
Sign In or Register to comment.