0

I am currently working on coding a PLC to execute certain commands in which I would like to be performed at specific scan cycles.

Is there a way I could code a program in Structured Text to where I can flag statements to only execute at an 'n' scan cycle?

Thanks in advance.

1 Answers1

1

You can use a counter that is incremented one for each scan cycle and then a case structure to control which commands are active at each scan:

VAR
  i: INT;
END_VAR

(* Main code to be executed at each scan cycle *)
(* The commands could be either actions to MAIN() or separate POUs *)
i := i + 1;
IF i > 10 THEN
  i := 1;
END_IF;

CASE i OF
  1: (* Call one command *)
    Command1(); 
  2, 4, 6, 8, 10: (* These scans all call the same command *)
    Command2();
  5: (* Call 3 different commands *)
    Command3();
    Command4();
    Command5();
  (* Scans 3, 7 and 9 do nothing *)
END_CASE;
pboedker
  • 523
  • 1
  • 3
  • 17