Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
884 B
2
Indexable
Never
FUNCTION_BLOCK Regulator
VAR_INPUT
	Setpoint:INT;
	Calibrate:BOOL;
	switch:BOOL;
END_VAR
VAR_OUTPUT
	CalcPos:INT;
	Calibrating:BOOL;
	Step:BOOL;
	Direction:BOOL;
END_VAR
VAR
	stepPos:INT;
END_VAR

IF Calibrate THEN 
	IF switch THEN 
		Calibrating:=FALSE; 
		CalcPos:=0;
		Step:=FALSE; 
		ELSE
		calibrating:=TRUE;
		Step:=TRUE;
		Direction:=TRUE;
		END_IF
END_IF
IF Calibrating:=FALSE THEN 
	switch:=FALSE;
END_IF
// Back to normal mode
IF Calibrate = FALSE  THEN
	IF Setpoint>CalcPos AND NOT Direction THEN 
		Direction:=TRUE;
		ELSE IF Setpoint<CalcPos AND Direction THEN
		Direction:=FALSE;
		END_IF
	END_IF
	IF NOT (CalcPos=Setpoint) THEN 
		Step:=NOT Step;
		IF Step AND Direction THEN 
			CalcPos:=CalcPos+1;
			END_IF
			IF Step AND NOT Direction THEN 
				CalcPos:=CalcPos-1;
			END_IF
			ELSE
				Step:=Step;
			END_IF
	END_IF
Leave a Comment