Time to Execute For/Next Commands
John Ritz
Posts: 14
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
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 Williams
Applications Engineer, Parallax
Dallas, TX· USA
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.
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
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
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.
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
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
I appreciate your help!