1 / 36

SPiiPlus Training Class

SPiiPlus Training Class. Program Flow Commands. Program Execution. ACSPL+ programs execute 1 command “block” per controller cycle Normally 1 line of code = 1 command “block” Multiple commands can be on a single line, separated by semicolon (;)

brede
Télécharger la présentation

SPiiPlus Training Class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SPiiPlus Training Class Program Flow Commands

  2. Program Execution ACSPL+ programs execute 1 command “block” per controller cycle • Normally 1 line of code = 1 command “block” • Multiple commands can be on a single line, separated by semicolon (;) • Statements between BLOCK…END control structure are executed as one command “block” • Certain commands cannot be executed as a single block (background tasks, loops, array processing, subroutine calls, goto statements) After “block” executes, program flow moves to the next “block” in the sequence unless special program flow commands are used

  3. Program Execution vs. Motion Execution ACSPL+ provides dedicated motion commands for starting and ending motion. • Motion commands are executed in a single command “block” • After motion command is executed, program flow moves to the next command “block” unless special program flow commands are used This means that unless you explicitly program it, motion execution and program execution are decoupled.

  4. Program Execution vs. Motion Execution velocity time ENABLE (0) PTP/r (0), 10000 program execution time STOP

  5. Program Execution vs. Motion Execution velocity time STOP ENABLE (0) PTP/r (0), 10000 program execution time WAIT 2000

  6. Program Execution vs. Motion Execution velocity time ENABLE (0) PTP/r (0), 10000 STOP program execution time TILL MST(0).#MOVE = 1

  7. Program Flow Commands ACSPL+ provides dedicated program flow commands to control and manipulate program execution • IF…ELSEIF…ELSE…END • WHILE…END • LOOP…END • WAIT • TILL • GOTO • CALL…RET • START, STOP, PAUSE, RESUME

  8. IF…ELSEIF…ELSE…END IF statement is one of the most basic conditional programming constructs • IF statement checks if conditional expression is true (evaluates to non-zero), and if it is true it will only execute its command list • If false (evaluates to zero), it will check the next ELSEIF statement to see if its expression is true, and if it is true it will only execute its command list • If the IF and ELSEIF statements are all false, it will execute the ELSE statements command list • IF statement is terminated with an END statement • ELSEIF and ELSE statements are optional

  9. IF…ELSEIF…ELSE…END Syntax: IF (conditional expression) (command list) [ELSEIF (conditional expression)] [(command list)] [ELSE] [(command list)] END

  10. IF…ELSEIF…ELSE…END Example:

  11. WHILE…END WHILE loop is a basic program flow statement that allows code to be executed repeatedly • WHILE statement checks if conditional expression is true (evaluates to non-zero), and if it is true it will execute its command list • WHILE statement will repeatedly execute command list until expression is false (evaluates to zero) • WHILE statement is terminated with an END statement

  12. WHILE…END Syntax: WHILE (conditional expression) (command list) END

  13. WHILE…END Example:

  14. LOOP…END LOOP is another basic program flow statement that allows code to be executed repeatedly • LOOPstatement evaluates expression and executes command list with that many iterations • If expression evaluates to zero or negative number, command list is not executed • If expression evaluates to non-integer number, it will be rounded to closest integer • Expression is only evaluated the first time the loop executes (it is not re-evaluated every iteration) • LOOP statement is terminated with an END statement

  15. LOOP…END Syntax: LOOP (expression) (command list) END

  16. LOOP…END Example:

  17. WAIT WAIT is a special program statement that delays program execution • WAIT statement evaluates expression and delays program execution for the specified number of milliseconds • If expression evaluates to zero or negative number, no wait occurs • Expression is rounded to nearest control cycle interval (typically 0.5 or 1 millisecond)

  18. WAIT Syntax: WAIT (expression)

  19. WAIT Example:

  20. TILL TILL is another special program statement that delays program execution • TILL statement checks conditional expression and delays program execution until the expression becomes true (evaluates to non-zero) • TILL has an optional timeout argument that will set a maximum delay time in milliseconds • If a timeout is used, the user can check the conditional expression after the delay to see if the timeout occurred

  21. TILL Syntax: TILL (expression) [, (timeout)]

  22. TILL Example:

  23. Program Labels Program labels are special programming constructs used to provide entrances into programs • Used by GOTO, CALL, and START program flow commands • Can be any alphanumeric sequence that must begin with a letter, end with a colon : and can also include the underscore _ • Many labels can exist within a program buffer, but each name must be unique • Same label name can be used in different program buffers • A special label called AUTOEXEC is known by the firmware • Any buffer with an AUTOEXEC is automatically started at the AUTOEXEC label upon power up

  24. GOTO GOTO is a program flow command that transfers program execution to a specified label • GOTO behaves as a program jump and never returns control back to the GOTO statement • GOTO can only transfer program execution to a label in the same buffer (cannot GOTO a different buffer) • GOTO should not be used to enter / exit a subroutine

  25. GOTO Syntax: GOTO (label)

  26. GOTO Example:

  27. CALL…RET CALL is a program flow command that is used to call a subroutine • CALL will transfer program execution to a specified label • After subroutine completes it must end in a RET command so program execution will return back to the where the CALL was executed • A CALL stack is implemented so that nested subroutine calls can be used • CALL can only call subroutines within the same buffer

  28. CALL…RET Syntax: CALL (label) (label): … RET

  29. CALL…RET Example:

  30. START…STOP…PAUSE…RESUME START, STOP, PAUSE, and RESUME are special program management commands • START will execute another buffer at a specified label or line number • Will generate run-time error if starting buffer that is already executing • STOP will stop another buffer from executing • PAUSE will pause another buffers execution • RESUME will resume a paused buffer • Commands can be executed by a buffer or streamed from a host

  31. START…STOP…PAUSE…RESUME Syntax: START (buffer number), (line number or label) STOP (buffer number) PAUSE (buffer number) RESUME (buffer number)

  32. START…STOP…PAUSE…RESUME Example:

  33. ACSPL+ Programming Example: 1 • Load program “Programming 05 – ProgramFlow.prg” to the controller • Should populate buffer 21 • Open communication terminal and set it up to show DISP messages • From the communication terminal start buffer 21 at label ‘Begin’ (“START 21, BEGIN”). Follow the instructions on the screen What happens?

  34. ACSPL+ Programming Example: 2 • Copy previous examples code into buffer 22 • Modify code so that after the data collection has completed, run_dc = 0, the arrays will be re-organized so the last collected data point will be at the end of the array

  35. ACSPL+ Programming Example: 3 • Open program buffer 23 • Write a routine to calculate the index of the maximum value of the first column of an array of a given length and display both the index and value to the communication terminal • Test the routine on the analog input array from example 2

  36. ACSPL+ Programming Example: 4 • Open program buffer 24 • Write a routine that will do a simple moving average of the input array and test on the analog input array from example 2. • Plot the filtered analog input data vs. the actual

More Related