1 / 17

SPiiPlus Training Class

SPiiPlus Training Class. Autoroutines, Subroutines and Function Calls. Structured Applications. Every programmer has his/her own way of structuring their application. While there is no wrong way of creating this structure in ACSPL+, there are consequences that must be considered.

deo
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. 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 Autoroutines, Subroutines and Function Calls

  2. Structured Applications Every programmer has his/her own way of structuring their application. While there is no wrong way of creating this structure in ACSPL+, there are consequences that must be considered. The important programming structures in ACSPL+ are: • Subroutines / Function calls • Autoroutines / Interrupts

  3. Subroutines / Function Calls Subroutines calls are supported in ACSPL+ using the CALL…RET commands. • Function calls are not explicitly supported, but can be created by using subroutines and local variables. Using subroutines / function calls can be very helpful for organizing a program. • Labels provide high level description of routine • Routines are easily reused • Routines can be removed from application by simply commenting out the CALL command

  4. Subroutines / Function Calls Subroutines / function calls have certain limitations that should be considered when using them. • CALL always takes 1 controller cycle to execute (regardless if in a BLOCK…END statement) • RET can return in the same controller cycle • A buffer program can only call a subroutine that exists in the same buffer program • Parameters cannot be directly passed into / out of a subroutine (must explicitly define variables)

  5. Subroutines / Function Calls Basic Example: A linear axis has 3 different modes of operation: normal mode, homing mode, and scanning mode. • Normal Mode • Maximum velocity, acceleration, and jerk parameters are used • Homing Mode • For safety, lower velocity, acceleration, jerk and current limits (XCURI, XCURV) are used • Scanning Mode • Low velocity is used Subroutines can be used to switch between the different modes.

  6. Subroutines / Function Calls GLOBAL INTmode; mode = 0 GLOBAL INTX; X = 0 STOP Switch_Modes: IF ( mode = 0 ) ! Normal mode CALLNormal_Mode ELSEIF ( mode = 1 ) ! Homing mode CALLHoming_Mode ELSEIF ( mode = 2 ) ! Scanning mode CALLScanning_Mode END STOP Normal_Mode: VEL(X) = 1000 ACC(X) = 10000 DEC(X) = 10000 JERK(X) = 100000 XCURI(X) = 50 XCURV(X) = 100 RET Homing_Mode: VEL(X) = 10 ACC(X) = 1000 DEC(X) = 1000 JERK(X) = 10000 XCURI(X) = 25 XCURV(X) = 25 RET Scanning_Mode: VEL(X) = 1 ACC(X) = 10000 DEC(X) = 10000 JERK(X) = 100000 XCURI(X) = 50 XCURV(X) = 100 RET

  7. Subroutines / Function Calls Basic Example: An application requires an axis to scan between two points (P0 and P1) at a constant velocity. In order to make sure the axis is at a constant velocity, the move needs to include a ramp up and ramp down displacement. A routine is used that is passed the two positions, velocity, acceleration, deceleration, and calculates the ramp up and ramp down displacements.

  8. Subroutines / Function Calls ! Global variables GLOBAL REALP0, P1 ! Local Variables REAL flVel REALflAcc REAL flDec REALflRampUp, flRampDown REALt ! Set function inputs flVel = VEL(0) flAcc = ACC(0) flDec = DEC(0) CALLCalc_Displacement DISP"Ramp up displacement = %f", flRampUp DISP"Ramp down displacement = %f", flRampDown STOP Calc_Displacement: ! Assume 2nd order calculation ! Calculate Ramp Up t = flVel / flAcc flRampUp = 0.5 * flAcc * pow(t, 2) ! Calculate Ramp Down t = flVel / flDec flRampDown = 0.5 * flAcc * pow(t, 2) RET

  9. Autoroutines / Interrupts Autoroutines / Interrupts are supported in ACSPL+ using the ON…RET commands. Autoroutines are very useful when trying to write a routine that will automatically trigger when some condition becomes true. Examples include: • Fault Handling • Interlocks • PLC algorithms • Logging

  10. Autoroutines / Interrupts Autoroutines can reside in any program buffer, but have a unique way in which they work. • Autoroutines are never directly executed (you do not CALL an autoroutine) • Autoroutines trigger based on a conditional expression. If edge-triggered (expression goes from false to true), the autoroutine body will be executed • An autoroutine is ready to trigger as soon as the buffer is compiled • Multiple autoroutines can reside in a single buffer • Autoroutines share local variables with the program buffer in which it resides

  11. Autoroutines / Interrupts Autoroutines / interrupts have certain limitations that should be considered when using them. • If an autoroutine is triggered and the program buffer it resides in is executing, the buffer will pause until the autoroutine finishes • If an autoroutine is executing in a buffer, and another autoroutine in the same buffer is triggered, it must wait for the first to complete • If an autoroutine is executed, it will not execute again until it is edge triggered (condition goes false and then true again)

  12. Autoroutines / Interrupts When working with autoroutines, it is sometimes necessary to disable or remove them. To disable all autoroutines in a program buffer, you set PFLAGS().#NOAUTO (bit 0). To re-enable them, you clear PFLAGS().#NOAUTO To remove an autoroutine, you need to re-compile the buffer with the code removed or commented out.

  13. Autoroutines / Interrupts Basic Example: A conveyor system has two sensors used to detect when a product is present. If either of the sensors are on, a single output is used to inform an upstream PLC.

  14. Autoroutines / Interrupts STOP ! Rising edge trigger ON ( (IN(0).0 = 1) | (IN(0).1 = 1) ); BLOCK OUT(0).0 = 1 END; RET ! Falling edge trigger ON ^( (IN(0).0 = 1) | (IN(0).1 = 1) ); BLOCK OUT(0).0 = 0 END; RET

  15. ACSPL+ Programming Example: 1 When error-mapping is used on the controller with the CONNECT function, the HALT command should be used for the limit switches instead of the KILL command. Write custom autoroutines for the left and right limit switches on axis 1 to HALT the axis whenever the autoroutine is triggered, and to only allow motion out of the limit.

  16. ACSPL+ Programming Example: 2 An operator terminal has two push-buttons used for diagnostic purposes. Whenever the user pushes the first button (IN(0).0), the current state and motion parameters of axis 1 (FPOS(1), MST(1), VEL(1), ACC(1), DEC(1) and JERK(1)) are logged in an array. Whenever the user pushes the second button (IN(0).1), the array is saved to flash memory. Write custom autoroutines to handle these requirements.

  17. ACSPL+ Programming Example: 3 A system has a safety interrupt (IN(0).0) such that whenever it is on, axis 1 cannot be commanded to move. Write a custom autoroutine to handle this requirement.

More Related