November 22, 2024, 09:05:57 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Code Executing Time

Started by Tim-M, February 19, 2008, 09:29:50 AM

Previous topic - Next topic

Tim-M

Rather than using pauses in programming, I'd like to use looping code something like the concept below to make better use of this time.  I think I can work the code out OK, but my question has to do with how long a loop like this might take to execute??  Can anyone give me a rough idea of the loop time or tell me how this can be figured out so that I can write code to fit several known times that I will have to match?  Is this a case where I just use the published lines per second spec and test from there for the particular code being run?  Thanks,  -Tim

FOR Loop = 1 TO X
Check input 1... IF/THEN
Check input 2... IF/THEN
NEXT X

As the timing requirements change from stage to stage within the program, the value of X can be changed to adjust time at the beginning of that stage of code.

JonnyMac

It's really difficult to gauge because the instructions have to be fetched from an EEPROM and then decoded before execution.  Parallax may have a better answer, but think you'll see something on the order of 150 microseconds per instruction.  One way would be to validate with a 'scope using a simple program:

Main:
  HIGH 0
  LOW 0
  GOTO Main


HIGH and LOW should execute in the same amount of time, so you can deduce the duration of GOTO by subtracting that time from the period that the output is measured low.

Some instructions have built-in delays.  SEROUT, for example, will require time to send the data and that will depend on the baud rate used.


Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

Thanks Jon, that's what I needed to know.  It sounds like the best way to know for sure is to test the actual code loop being used and proceed from there.  Time to get out the scope and measure some timing.

By the way, I can talk a little more about this project.  This is an additional control for a PVC welding machine that will allow it to run automatically, or cycle through its sequence on its own.  This is the same control that will use the selector switch via the POT command that we've talked about in another thread.  The timing issue here, has to do with how long it takes for the mechanics of the machine to move from position to position.  The time ranges from 2-30 seconds, or just short of 30 seconds.

JonnyMac

That is really the best way.  Quite some time ago I creates a BS2-based alarm product that used a state machine.  I ended up manually timing and padding every section of code so that any path was almost dead-on 100 ms; this gave me a time base to work with in the program.  It took a day to do the timing/padding, but in the end we had a product that went to idea to ready for production in under three weeks -- the company was pretty happy about that.  Since it was a specialty thing and there was a lot of margin in the product, the BASIC Stamp went from being a hobbyist toy (in their eyes) to a real problem solver.
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

That's really cool Jon...  Did the product make it to market?

Basic Stamps may not be the fastest microprocessors to be had, but they are versitile and can be powerful in the hands of a good programmer, that's for sure.

JonnyMac

It was accessory offered by Flowtronex, a company that has since been folded into a bigger corporation.  Last I heard they were still building and selling them.  The product is called HotWire (not my choice) and it was funny that we couldn't get HotWire.com as a domain... then about six months later the travel service showed up and we understood why.
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

February 19, 2008, 11:52:27 AM #6 Last Edit: February 19, 2008, 12:50:27 PM by Tim-M
Thanks for telling us a little more about the product.  I hope it did well for you Jon.

Tim

Caretaker.CCI

OK... is this an appropriate thread to discuss "state machine"? That term has popped up in several other threads and I confess, I don't know what this is referring to. Perhaps just a quick definition to get us started and then I will know where to begin my research (and where to post).

JonnyMac

Do me a favor and ask it in the Programming Techniques forum; let's not hijack this thread.
Jon McPhalen
EFX-TEK Hollywood Office