Delta Tau Forums
Homing Routine Timers - Printable Version

+- Delta Tau Forums (http://forums.deltatau.com)
+-- Forum: Delta Tau Data Systems (http://forums.deltatau.com/forumdisplay.php?fid=1)
+--- Forum: Power PMAC (http://forums.deltatau.com/forumdisplay.php?fid=2)
+--- Thread: Homing Routine Timers (/showthread.php?tid=2930)



Homing Routine Timers - jmitchell@optomec.com - 07-13-2019

Here is a snippet for X axis in my Home.plc

I understand the concept about calling Timers in a subroutine via creating a subroutine in the Libraries folder, but I would like to keep the execution as local as possible to the plc. The variable I'm most concerned with is AXIS1_DWELL_TIME.

Any insight or constructive criticism to optimize or clean up this routine would be appreciated.

I've included the snippet in a file as well because of the formatting within this thread window.

/**********************
AXIS 1
**********************/
// WATCH FOR MOTOR #1 HOME COMMAND
if ((AXIS1_HOME_STATE == 0 && M1_HOME_INPROGRESS == 1) &&
(AXIS1_HOME_POS != 0)){
AXIS1_HOME_STATE=1;
}

// WAIT FOR AXIS TO BE AT HOME OFFSET POS
if (AXIS1_HOME_STATE == 1 && abs(M1_ACTUAL_VELOCITY) < 1000 &&
M1_IN_POS == 1 && M1_HOME_COMPLETE == 1){
if (AXIS1_TIMER_STARTED==0){
AXIS1_DWELL_TIME = (200 * 8388608)/Sys.ServoPeriod;
TIMER5_START = Sys.ServoCount;
AXIS1_TIMER_STARTED = 1;
}
TIMER5_ELAPSED = Sys.ServoCount - TIMER5_START;

AXIS1_HOME_OFF_COMPARE = abs(M1_COUNTER_POS - M1_HOME_POS) -
abs(M1_HOMEOFFSET/16);

if (AXIS1_TIMER_STARTED == 1 && TIMER5_ELAPSED >
AXIS1_DWELL_TIME && abs(AXIS1_HOME_OFF_COMPARE) <
AXIS1_AT_HOME_BANDWIDTH){
AXIS1_TIMER_STARTED = 0;
AXIS1_HOME_COMPLETE = 0;
AXIS1_HOME_STATE = 2;
}
}
close


RE: Homing Routine Timers - Eric Hotchkiss - 07-15-2019

One option is to put the timer into a subroutine inside the PLC instead of a subprogram. In the below example, PLC 1 uses a subprogram timer to increment P1 every second while PLC 2 uses a subroutine.

Calling the subroutine does not allow variable passing, so you will need to handle that on your own if you use this method.

Code:
OPEN PLC 1
P1++
CALL DelayTimer.sec(1)
CLOSE

OPEN PLC 2
P2++
Gosub 999
RETURN
N999:
LOCAL EndTimeSec
EndTimeSec = Sys.Time + 1
WHILE (EndTimeSec > Sys.Time) {}
RETURN
CLOSE