Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

TON ST Simulation

2018-03-08
2018-03-09
  • BrotherMaestro - 2018-03-08

    Hello Team,

    Ran into quite a baffling situation.
    I am able to easily setup and run a TON timer when using the CFC style of graphic code...
    However, I find in certain setups the ST version doesn't function

    Is this a limitation of the software? Or a Bug? Or is there something I am missing?
    (I am running the code in Simulation, as I have no machine to deploy to at this time.
    Both run under the Main task in a PRG POU)

    ST Attempt 1 (Simple works correctly)

    VAR
       TON_1 : TON;   
       TimeOut  : BOOL;
       ValueIN : BOOl;
    END_VAR
    TON_1( IN:= ValueIN, PT:= T#5S);
    TimeOut := TON_1.Q; 
    

    ST Attempt 2 (Complex, doesn't work)

    VAR
       TON_2 : TON;
       ValueIN : BOOL := TRUE;
       OUT : BOOL;
       Delay : TIME := T#5S;
       
    END_VAR
    TON_2.PT := Delay;
    TON_2.IN := ValueIN;
    OUT := TON_2.Q;
    

    TON_2.ET doesn't count up at all, despite TON_2.IN Being TRUE.
    I decided to place the TON_2.PT in an init IF statement so it only runs once, and still nothing happened with the timer.

    I am curious why this is the case?

     
  • plcmax - 2018-03-08

    Hi,
    you never call the instance of the timer(you just set the Inputs of the instance)
    TON_2();

    Regards
    plcmax

     
  • BrotherMaestro - 2018-03-09

    Ah, That makes sense now.
    Did some testing with your suggestion.

    I now understand that the internal variables are only updated during a call of TON_1().
    However, after the first call, the actual timer continues on without the need of TON_1 being called.

    So correct me if I am wrong,
    but I understand that you only need to call TON_1() twice for a single use of the TON?
    Once to start the timer.
    Once to update the variables AFTER PT has expired.
    However in practice this isn't possible, which is why we check each loop of the program (or use an internal for/while loop) to continuously update the internal variables.

     

Log in to post a comment.