(* PLC System Bits: First Scan and Clock Pulses — Control Panel scene X1 = Start (N.O.) X2 = Stop (N.C., TRUE when not pressed) X3 = Jog, used here as Acknowledge Y1 = Motor run light SB3 = first scan SB5 = 0.5 s clock SB6 = 1 s clock No timers: the clocks do the timing. *) VAR StartRise : R_TRIG; // rising edge of Start SecondPulse : R_TRIG; // rising edge of the 1 s clock MotorRun : BOOL; // seal-in PowerUp : BOOL; // power-up flag, needs acknowledge TimeDone : BOOL; // run time reached RunSeconds : INT; // seconds the motor has run RunPreset : INT; // run time preset END_VAR (* FIRST SCAN — TRUE for one scan after STOP to RUN *) IF SB3 THEN PowerUp := TRUE; RunPreset := 10; RunSeconds := 0; END_IF; (* ACKNOWLEDGE — Jog clears the power-up flag *) IF X3 THEN PowerUp := FALSE; END_IF; (* NEW RUN — each Start press zeroes the run seconds *) StartRise(CLK := X1); IF StartRise.Q AND NOT PowerUp THEN RunSeconds := 0; END_IF; TimeDone := RunSeconds >= RunPreset; (* MOTOR RUN — seal-in; Stop, power-up flag and run time done drop it *) MotorRun := (X1 OR MotorRun) AND X2 AND NOT PowerUp AND NOT TimeDone; (* RUN SECONDS — one count per rising edge of the 1 s clock *) SecondPulse(CLK := SB6); IF SecondPulse.Q AND MotorRun THEN RunSeconds := RunSeconds + 1; END_IF; (* PILOT LIGHT — steady = running, fast flash = acknowledge, slow flash = done *) Y1 := MotorRun OR (PowerUp AND SB5) OR (TimeDone AND SB6);