Shop OBEX P1 Docs P2 Docs Learn Events
Time to Execute For/Next Commands — Parallax Forums

Time to Execute For/Next Commands

John RitzJohn Ritz Posts: 14
edited 2005-01-20 16:39 in BASIC Stamp
Greetings!

Using a BS2, I need to do a delay less than 1 ms, so the pause staement is not an option. I am thinking I can do a for/next loop for x number of iterations, if only I new the overhead time per loop on a for/next loop.

For example, I need to delay for 0.8 us. To do that, I am thinking I can use the following code:

for·i = 1 to ???

next

So what would ??? be to get 0.8us. Is there somewhere where the code overhead time for the for/next commands is documented? I already checked the BS2 manual, and it doesn't say.

Thanks for any help!

John

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-19 19:08
    You will not be able to do that with a BASIC Stamp -- the instruction load times are more than 100 microseconds. If you really need fractional microsecond delays, then the SX and assembly langauge are the path you may have to take.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John RitzJohn Ritz Posts: 14
    edited 2005-01-19 20:02
    Ok, thank you!

    I will probably just rig something with a 555 timer for the time being, since I have a couple lying around. It is a 1/1200 second pulse I need to generate for IR commands.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-01-19 20:51
    John -

    Although Jon has given you the final answer for your specfic needs, you may find the instruction timing information in the link below to be of use in the future:
    http://www.emesystems.com/BS2speed.htm

    Thanks go to Dr. Tracy Allen.

    Regards,

    Bruce Bates
  • John RitzJohn Ritz Posts: 14
    edited 2005-01-19 22:12
    Thanks, Bruce! That will come in handy.

    But one question I still have is the specs of the BS2, which say that the BS2 executes on average 4000 intructions per second. If that is the case, then there should be some commands that are executed in far less time than 1 ms. Is it possible to string some of those together to get close to 0.8 us, even if they are used as dummy commands for timing only?

    UPDATE: After looking through the command execution times in the URL Bruce has provided, I may be able to string a couple together to get a close approximation of 0.8us. That may suffice, as the IR receiver may have a tolerance for noise that will be forgiving of 15-20 or so microseconds off. It's worth a try, anyways [noparse];)[/noparse]

    Post Edited (John Ritz) : 1/19/2005 10:26:33 PM GMT
  • BeanBean Posts: 8,129
    edited 2005-01-19 22:27
    John,
    I think you are confusing people. When you say you need "0.8 us" do you mean 0.8 microseconds ? If so there is no way to do that with the stamp alone.

    Bean.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-01-19 22:37
    John -

    What you may be missing is that the Stamp PBASIC is an interpreted language. Your instructions (whatever they may be) are never executed in native form per se. Each tokenized Stamp PBASIC command, which was issued by the programmer, is extracted from EEPROM, examined, and an appropriate routine internal to the PBASIC system (in native mode) executes to perform the function you wish to perform. The time to fetch your command from EEPROM is in excess of the time you wish to "fudge". Thus, no command will provide that short a time frame. This is all according to Jon's statement: "the instruction load times are more than 100 microseconds", and I certanly have no reason to dispute that.

    I hope that makes some sense now.

    As regards your 555 idea, just remember that they are not terribly accurate, primarily due to the temperature effects on, and innate lack of tolerence of, the capacitors and resistors used in the circuitry. You may be better off with some circuity driven by a crystal oscillator, with the frequency divided down to an appropriate frequency, or something of that nature.

    Regards,

    Bruce Bates
  • John RitzJohn Ritz Posts: 14
    edited 2005-01-20 15:54
    My apologies! Bean is correct; I am confusing everyone. I meant 0.8 ms, or to be more precise 830 us. Now that I've wiped the egg off my face, can that be accomplished? rolleyes.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 16:36
    800 microseconds -- now you may be able to pull things off. Try this:

    PAUSE 0

    Yes, it's legal. The only delay is the load time. You may have to duplicate this line a couple times to get close. Or you could try a loop -- but I think you're going to need to do thing emperically to work out the exact timing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John RitzJohn Ritz Posts: 14
    edited 2005-01-20 16:39
    Thanks, Jon! Sorry about the confusion earlier. I will experiment to try to get the right timing.

    I appreciate your help!
Sign In or Register to comment.