Shop OBEX P1 Docs P2 Docs Learn Events
Optimization of DO...LOOP and SELECT...CASE...ENDSELECT commands — Parallax Forums

Optimization of DO...LOOP and SELECT...CASE...ENDSELECT commands

Hello, this is my first time on the forums, but I'm looking for some assistance increasing the speed at which a program operates on the BS2 Stamp chip in a Board of Education Bot. I am involved in a robotics competition where we are timed in our attempt to go through a maze while crossing certain specified checkpoints. With the completion of my code and the upgrading of my servos to High-Speed Servos, my Bot now drives so fast that the SELECT...CASE command sometimes does not pick up on the markers that tell it where it is in the maze. If anyone has any general tips on optimizing the DO...LOOP or SELECT...CASE...ENDSELECT commands, that would be great, and if need be, I can post portions of my program for more detailed analysis.
Thanks!

Comments

  • There's not much optimization you can do with DO...LOOP statements. They translate internally into straightforward IF...THEN and GOTO statements. SELECT...CASE...ENDSELECT is another thing. Each case translates into an IF...THEN statement. If you have a lot of cases and the frequently executed ones are near the end, there are a lot of unsuccessful IF...THEN statements that get executed. Put the most frequently executed cases at the beginning. Beyond that, you'd really have to provide your code for examination.
  • If you could post your code that would help others help you fine-tune it.

    In addition to Mike's suggestions, some programs lend themselves to LOOKDOWN and LOOKUP tables. SELECT..CASE in the Basic Stamp works, but generates a lot of code to handle all the details -- this has an impact on execution speed.
  • The BRANCH command and its derivatives, ON .. GOTO and ON ... GOSUB are quite efficient. In DO LOOPS, the construction DO WHILE ... LOOP is slower than DO ... LOOP WHILE. But savings from those optimizations are more like a millisecond here and another there, so the slowness your Bot is feeling may lie elsewhere in its program structure.
Sign In or Register to comment.