Kendrion Kuhnke Automation GmbH
Counter2, Counter/Posi2
35
17 May 2021
Examples
Enable Counter
The counter remains enabled for as long as variable "EnableCounter_1" is TRUE.
Term2_EnableCounter_1:=TRUE;
(*Enables the counter*)
Term2_Counting_1;
(*TRUE if the counter is enabled*)
Term2_Clockwise_1;
(*TRUE if counting up*)
Set / Clear Counter
A rising edge of "SetCounter_1" accepts the value of "SetValue_1" as the actual counter value.
"CounterSet_1=TRUE" indicates that the function is running.
Returning "SetCounter_1" to FALSE also returns "CounterSet_1" to FALSE.
Term2_SetValue_1:=diCounterValue ; (*Write value to register*)
(* 0 = clear*)
Term2_SetCounter_1:=TRUE;
(*and accept as actual counter value*)
Term2_CounterSet_1;
(*TRUE when accepted*)
Set Reference Value
A rising edge of control bit "SetOptions_1" accepts the configuration settings set in "Counter 1 Options".
Status bit "OptionsSet_1" confirms that the settings have been accepted.
Example: set up the reference value function.
PROGRAM Initialise
VAR
bInit: BOOL := TRUE ;
Step: USINT;
END_VAR
--------------------------------------------------------------------------------
IF bInit THEN
CASE Step OF
(*Choose options and accept with rising edge of "Set_Options"*)
0:
Term2_EnableCounter_1:=TRUE;
(*Enable counter*)
Term2_EnableCompare_1:=TRUE;
(*Enable reference function*)
Term2_ControlOutput_1:=TRUE;
(*Reference function sets output*)
Term2_SetValue_1:=10000;
(*Value set = 10000..*)
Term2_SetCompare_1:=TRUE;
(*..is used as reference value*)
Term2_SetOptions_1:=TRUE;
(*Accept*)
Step:= 1;
(*Wait until accepting "OptionsSet" and "CompareSet" has been confirmed*)
1:
IF Term2_OptionsSet_1 AND Term2_CompareSet_1 THEN
Step:= 2;
END_IF
(*Reset "Set_Options" and " SetCompare" to default*)
2:
Term2_SetOptions_1:=FALSE;
Term2_SetCompare_1:=FALSE;
Step:=0;
bInit:=FALSE;
END_CASE
END_IF