Timed ramps and dwells - a FUNCTION example

Timed ramps and dwells - a FUNCTION example

Functions to make timed position ramps and dwells. For example as might be used in a blow moulding controller.

' Function library to support timed ramps
'
'Declare a universal value to hold the table index
DIM tab_index AS INTEGER

' Set up a linear TABLE
FUNCTION set_tab(index AS INTEGER, local_units AS FLOAT)
     DIM i, c AS INTEGER
     c = 0
     FOR i = index TO index + 10
          TABLE(i, c * local_units / 10)
          c = c + 1
     NEXT i
     tab_index = index
ENDFUNC

FUNCTION print_index()
     PRINT #0, tab_index
ENDFUNC

FUNCTION move_time(target_dist, ramp_time AS FLOAT)
     SPEED = 100 / ramp_time
     ACC(SPEED * 1000)
     CAM(tab_index, tab_index + 10, target_dist, 100)
ENDFUNC

FUNCTION dwell(d_time AS FLOAT)
     WA(d_time * 1000000 / SERVO_PERIOD)
ENDFUNC

Example program:

' For blow moulding applications, a sequnce is needed that ramps up an axis over a period of time
' then applies a delay before doing another ramp at a different set rate.
' The sequence is as follows:
' move_time(target_position1, ramp_time1)
' dwell(dwell_time1)
' move_time(target_position2, ramp_time2)
' dwell(dwell_time2)
' move_time(target_position3, ramp_time3)
' dwell(dwell_time3)

' The TrioBASIC command that fits a change in position over a set time is CAM.
' With a linear ramp in the TABLE, it will represent a move over time.

' setup the axis
BASE(10)
UNITS = 50
SERVO = ON
WDOG = ON
DEFPOS(0)

set_tab(100, UNITS)

TRIGGER ' start the scope

move_time(100, 2.5)
WAIT IDLE
dwell(1)
move_time(50, 3.25)
WAIT IDLE
dwell(1.5)
move_time(50, 2.0)
WAIT IDLE
dwell(1.5)
move_time(-200, 5.0)
WAIT IDLE



    • Related Articles

    • Uniplay List Box Function Example - Alarm Listing Example

      CODE EXAMPLE: ALARM (program) 'Alarm message triggered by changing "alarm_number" value. 'Other logic to be done to facilitate this. DIM clock_alarm1 AS STRING(64) DIM clock_alarm2 AS STRING(64) DIM clock_alarm3 AS STRING(64) DIM clock_alarm4 AS ...
    • AN-338 Creating User Function Block in IEC-61131-3

      This document is a quick guide to creating and using a User Function Block in IEC61131-3 programming
    • AN-389 VRSTRING 16 bits TrioBASIC Function

      VRSTRING combines the contents of an array of VR() variables so that they can be printed as a text string or used as part of a STRING variable. This document explains with an example code.
    • Set and Clear bits in TABLE values (Function)

      Here are 2 functions to set and clear a bit in a given TABLE value. ' functions to set and clear bits in TABLE FUNCTION set_table_bit(index, bit AS INTEGER)   DIM pattern AS INTEGER   pattern = 1 << bit   TABLE(index, TABLE(index) OR pattern) ENDFUNC ...
    • Ethernet Modbus TCP VR mapping, ETHERNET function

      Q. I want to compile the existing project and the compiler says it has problems with the ETHERNET command. A. I can see the MC403 which does not work has 2.0268 which is relatively old. The controller that does work has a different firmware version. ...