Spiiplus training class
This presentation is the property of its rightful owner.
Sponsored Links
1 / 36

SPiiPlus Training Class PowerPoint PPT Presentation


  • 169 Views
  • Uploaded on
  • Presentation posted in: General

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 (;)

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Spiiplus training class

SPiiPlus Training Class

Program Flow Commands


Program execution

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


Program execution vs motion execution

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.


Program execution vs motion execution1

Program Execution vs. Motion Execution

velocity

time

ENABLE (0)

PTP/r (0), 10000

program execution

time

STOP


Program execution vs motion execution2

Program Execution vs. Motion Execution

velocity

time

STOP

ENABLE (0)

PTP/r (0), 10000

program execution

time

WAIT 2000


Program execution vs motion execution3

Program Execution vs. Motion Execution

velocity

time

ENABLE (0)

PTP/r (0), 10000

STOP

program execution

time

TILL MST(0).#MOVE = 1


Program flow commands

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


If elseif else end

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


If elseif else end1

IF…ELSEIF…ELSE…END

Syntax:

IF (conditional expression)

(command list)

[ELSEIF (conditional expression)]

[(command list)]

[ELSE]

[(command list)]

END


If elseif else end2

IF…ELSEIF…ELSE…END

Example:


While end

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


While end1

WHILE…END

Syntax:

WHILE (conditional expression)

(command list)

END


While end2

WHILE…END

Example:


Loop end

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


Loop end1

LOOP…END

Syntax:

LOOP (expression)

(command list)

END


Loop end2

LOOP…END

Example:


Spiiplus training class

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)


Spiiplus training class

WAIT

Syntax:

WAIT (expression)


Spiiplus training class

WAIT

Example:


Spiiplus training class

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


Spiiplus training class

TILL

Syntax:

TILL (expression) [, (timeout)]


Spiiplus training class

TILL

Example:


Program labels

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


Spiiplus training class

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


Spiiplus training class

GOTO

Syntax:

GOTO (label)


Spiiplus training class

GOTO

Example:


Call ret

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


Call ret1

CALL…RET

Syntax:

CALL (label)

(label):

RET


Call ret2

CALL…RET

Example:


Start stop pause resume

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


Start stop pause resume1

START…STOP…PAUSE…RESUME

Syntax:

START (buffer number), (line number or label)

STOP (buffer number)

PAUSE (buffer number)

RESUME (buffer number)


Start stop pause resume2

START…STOP…PAUSE…RESUME

Example:


Acspl programming example 1

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?


Acspl programming example 2

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


Acspl programming example 3

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


Acspl programming example 4

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


  • Login