*
FUNCTION_BLOCK "M_1DRCT"
TITLE =1 DIRECTION DRIVE
//this simple function_block realize the control of a one direction drive.
//all functions of the drive are monitored and avaible at wRetVal.
//an error also will switch off the EN0 of the function_block.
//
//wRetVal - status
//----------------
//0000 - enable and ready to go
//0001 - start drive
//0003 - start drive and contactor on
//0007 - drive run and all functions ok
//
//wRetVal - error
//---------------
//8000 - no extern enable
//8001 - protectswitch off
//8002 - repairswitch off
//8003 - protectswitch and repairswitch off
//8004 - contactor had not switched in time or is gone
//8005 - motioncontrol had not switched in time or is gone
//
//DATE: 05.08.2008
//AUTHOR: 4lagig
//VERSION: V0.1 BasicVer
AUTHOR : '4lagig'
VERSION : 0.1
VAR_INPUT
xPlcPulse : BOOL ; //plug the Mx.0 with 10Hz here
xEnable : BOOL ; //extern enable input (1=ON)
xProtectSwitch : BOOL ; //(1=OK)
xRepairSwitch : BOOL ; //(1=OK)
xContactor : BOOL ; //(1=ON)
xMotionControl : BOOL ; //(1=OK)
xStart : BOOL ; //(1=START)
iContactorTime : INT ; //normally a small number, maybe 10 (mean 1s)
iMotionControlTime : INT ; //a little more than the time the drive needs to run fullspeed
END_VAR
VAR_OUTPUT
xContactorOut : BOOL ; //the output for the drive
wRetVal : WORD ; //status/error information
END_VAR
VAR
xHelpFlagEnable : BOOL ;
xHelpFlagPlcPulse : BOOL ;
xTimeEnable : BOOL ;
xAllFine : BOOL ;
iTimer : INT ;
END_VAR
BEGIN
NETWORK
TITLE =
//
//enable and init the function_block
//
UN #xEnable; //if enable false then
R #xAllFine; //reset intern start enable
R #xContactorOut; //make sure contactor is off
SPBN nore;
L W#16#8000;
T #wRetVal; //write status information
SPA end; //and leave the function
nore: UN #xStart; //if start not and
SPBN ston;
R #xTimeEnable;
L W#16#0; //only enable and all switches on
T #wRetVal; //wRetVal = 0000
NETWORK
TITLE =
//
//init and take ready for trigger
//
ston: U #xEnable; //enable true
U #xStart; //and start
FP #xHelpFlagEnable; //new
SPBN nonw;
L W#16#1; //then
T #wRetVal; //write status information
L 0; //initialize
T #iTimer; //timer with zero
S #xTimeEnable; //and make enable
S #xAllFine; //set the intern enable
NETWORK
TITLE =
//
//check the function
//
nonw: UN #xProtectSwitch;
SPBN pok;
L W#16#8001; //if protectswitch off
UN #xRepairSwitch;
SPBN ron;
L W#16#8003; //if protectswitch and repairswitch off
ron: T #wRetVal; //write error information
R #xAllFine;
R #xContactorOut; //make sure contactor is off
SPA err; //and leave the function
pok: UN #xRepairSwitch;
SPBN rok;
L W#16#8002; //if repairswitch off
T #wRetVal; //write error information
R #xAllFine;
R #xContactorOut; //make sure contactor is off
SPA err; //and leave the function
NETWORK
TITLE =
//
//trigger the drive
//
rok: U #xStart; //if start on
U #xAllFine; //and intern enable also
= #xContactorOut; //do the drive
NETWORK
TITLE =
//
//start the timer for drive connections
//
U #xTimeEnable;
U #xAllFine; //the intern enable
U #xPlcPulse; //do with the PlcPulse
FP #xHelpFlagPlcPulse;
SPBN equ;
L #iTimer; //a timer
+ 1;
T #iTimer;
NETWORK
TITLE =
//
//stop if neccessary - contactor
//
equ: U( ;
L #iTimer; //if the time
L #iContactorTime; //bigger than the settime
>=I ; //for the contactor
) ;
UN #xContactor; //and the contactor off
SPBN cook;
L W#16#8004; //write wRetVal
T #wRetVal;
R #xAllFine; //and reset the intern enable
SPA err;
NETWORK
TITLE =
//
//write status, if contactor OK
//
cook: U #xContactor;
U #xStart;
SPBN noco; //contactor on
L W#16#3; //means 3
T #wRetVal;
NETWORK
TITLE =
//
//stop if neccessary - motion control
//
noco: U( ;
L #iTimer; //if the time
L #iMotionControlTime; //bigger than the settime
>=I ; //for the motion control
) ;
UN #xMotionControl; //and the motion control
SPBN mook;
L W#16#8005; //write wRetVal
T #wRetVal;
R #xAllFine; //and reset the intern enable
SPA err;
NETWORK
TITLE =
//
//write status if motion control OK
//
mook: U #xMotionControl;
U #xStart;
SPBN tim; //motion control on
L W#16#7; //means 7
T #wRetVal;
NETWORK
TITLE =
//
//stop the timer
//
tim: L #iMotionControlTime; //the big time
L 100; //+100
+I ;
L #iTimer;
<=I ;
SPBN end;
SET ;
R #xTimeEnable; //switch off the timer
NETWORK
TITLE =
//
//EN0-handling
//
end: L #wRetVal; //if the wRetVal
L W#16#8000; //bigger than 8000
>D ; //then is an error
SPB err; //and the EN0 are false
SET ; //else the EN0 are true
SAVE ;
err: NOP 0;
END_FUNCTION_BLOCK