Time Off Timer

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #8182
    AvatarRich Ex

    Hello friends ,
    I am trying to add a delay within a formula and things are not working right .

    I have a graphic in Webstation that is linked to a channel and the graphic changes when the channel changes from 0 to 1 . So far no problem .
    The thing is the real pulse on the channel is short , a few mS , so I want the graphic to stay ‘on’ for 10 seconds .
    In my code I have tried using Task.Delay , this did not work , I then tried using the datetime.now as a timer , this worked but stopped the whole Webstation from updating .
    Heres my code

    double FindStatus(int boardcnl,int transittimecnl) // get ip cnl & delay cnl
    double boardbit = Val(boardcnl);// setup variables
    double boardcnlstat = Stat(boardcnl);// setup variables
    double transittimeSecs = Val(transittimecnl);// setup variables
    DateTime tnow = DateTime.Now; // get current time for timer
    DateTime target = DateTime.Now.AddSeconds(transittimeSecs); // timer target
    int aa = 0; // setup variables

    if (boardcnlstat == 1)
    if (boardbit == 0 )
    return aa;
    if (boardbit == 1 )
    Val(aa); // update the cnl
    while (tnow < target) // DELAY target reached ?
    { tnow = DateTime.Now; }
    return aa;
    return aa;

    Any help please would be much appreciated .


    Hello Rich,

    I think, you need an extra channel of the calculated discrete type. A formula should check when the source input channel was changed from 0 to 1, then set the 2nd channel to 1 and remember a timestamp. After that compare current time with the timestamp to determine when to change the 2nd channel back to 0.

    Formulas must be calculated as fast as possible. Avoid delays, tasks and thread in formulas.


    Will the TP timer be enough for you, similar to how it is implemented in a PLC?



    Calling the formula Tp (Val(414), 10000) number of the monitored channel 414, time in milliseconds.
    When 1 appears in channel 414, the timer output will turn on, after 10 seconds it will turn off for this example. The timer starts working on the signal edge, no need to hold 1 in the controlled channel.

    The Ticks formula is used in all the timers I’ve done. The formulas must be added to the Formula Reference.

    • This reply was modified 1 month, 1 week ago by Avatarmanjey73.

    But this does not solve the problem of saving the pulse to the channel database when writing once per minute.

    AvatarRich Ex

    Thank you Mikhail , thank you Manjey .

    Yes I see that I should not add the delay in the formula . I will try what you said about making another channel and using a timestamp for comparison .

    As always thank you.


Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.