PLC programming: Simple pulser ST Question for beginner

53 views Asked by At

Writng a FB in ST on Beckhoff TC for a pulser which turns on and off on a cycle, is paused by turning bControlInput to FALSE, but resumes state where it was once unpaused. Given code below does not carry out the resume state function, can anyone give me a hand?

FUNCTION_BLOCK FB_Pulser
VAR_INPUT
    bControlInput :BOOL;
    tOffTime : TIME;
    tOnTime : TIME;
END_VAR
VAR_OUTPUT
    bOutput : BOOL;
END_VAR
VAR
    fbOffTimer : TON;
    fbOnTimer : TON;
    f_trig : F_TRIG;
    r_trig : R_TRIG;
    bOutputPaused : BOOL;

END_VAR


logic:

// Store output state when control input goes off
f_trig(CLK:=bControlInput);
IF f_trig.Q THEN
    bOutputPaused := bOutput; ///expect: bOutputPaused true, bOutput false
END_IF


// Resume output state when control input goes on
r_trig(CLK:=bControlInput);
IF r_trig.Q THEN
    bOutput := bOutputPaused;
END_IF


// Main control logic
IF bControlInput THEN
    IF NOT bOutput THEN
        //If output is off, start the off timer
        fbOffTimer(IN:=TRUE, PT:=tOffTime);

        // When the off timer completes, turn on the output
        IF fbOffTimer.Q THEN
            fbOffTimer(IN:=FALSE);
            bOutput := TRUE;
        END_IF
    ELSE
    // If output is on, start the on timer
        fbOnTimer(IN:=TRUE, PT:=tOnTime);

        // When the on timer completes, turn off the output
        IF fbOnTimer.Q THEN
            fbOnTimer(IN:=FALSE);
            bOutput := FALSE;
        END_IF
    END_IF
ELSE
    // If control input is off, ensure the output is off
    bOutput := FALSE;
END_IF

Have tried workarounds but to no avail

0

There are 0 answers