Creating a continuous counter using structured text language

akkinomo
2022-02-18
2022-02-18
  • akkinomo - 2022-02-18

    Please check the below is my code and I'm able to operate one cycle of up down counter but cannot operate continuously.
    Any suggestions?

    Declaration:

    PROGRAM PLC_PRG
    VAR
    T1:TON;
    C1:CTUD;
    SRT:BOOL;
    B: BOOL;
    A: BOOL;
    COUNT: INT;
    STP: BOOL;
    PRESET: INT;
    END_VAR

    Code:

    T1(IN:= SRT AND NOT T1.Q, PT:=T#1s);
    COUNT :=0;
    PRESET :=10;
    WHILE COUNT<PRESET DO
    C1(CU:= T1.Q AND NOT B, PV:=21);
    IF C1.QU = TRUE THEN
    B:=TRUE;
    A:=TRUE;
    END_IF;
    C1(CD:=T1.Q AND A);
    IF C1.CV = 0 THEN
    A:=FALSE;
    END_IF;
    COUNT := COUNT +1;
    END_WHILE;

     
  • dFx

    dFx - 2022-02-18

    Please read the documentation about the block you use before asking for help.

    Inputs:
    CU : BOOL; With each rising edge at this input the counter value (CV) is incremented by 1. When CV reaches or exceeds PV,
    QU will be set to TRUE.
    CD : BOOL; With each rising edge at this input the counter value (CV) is decremented by 1 until 0
    is reached.
    
     

Log in to post a comment.