FUNCTION_BLOCK "test_TON" { S7_Optimized_Access := 'TRUE' } VERSION : 0.1 VAR secTakt {InstructionName := 'TON_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TON_TIME; q { S7_SetPoint := 'True'} : Bool; secChange : Bool; secCount : Int; END_VAR VAR_TEMP tempInt : Int; tempBool : Bool; END_VAR BEGIN // https://www.lamaPLC.com // author: Sandor Vamos // 12.05.2023, with TIA 16 tested // Category: freeware // // FB "static" variables: // secTakt: TON_TIME // q, secChange: BOOL // secCount: INT // FB "temp" variables: // tempInt: INT // tempBool: BOOL // TON, as sec impuls generator #secTakt(IN:=NOT(#q), PT:=t#1s); // For example, the "Q" parameter can be called // directly when calling "secTakt", // OR it can be referred to as: #q := #secTakt.Q; // when the time has elapsed, the block will be called: // - secChange changes its status every second // - secCount increases every second, in the range 0..9 IF #q THEN #secChange := NOT (#secChange); #secCount := #secCount + 1; IF #secCount > 9 THEN #secCount := 0; END_IF; END_IF; // monitor #tempInt := #secCount; #tempBool := #secChange; END_FUNCTION_BLOCK