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

cycle task bit in Codesys?

Rob
2019-10-03
2019-10-03
  • Rob - 2019-10-03

    Hi all,
    I wanted to use a cyclic task to read a device status signal every minute.
    In doing so, every check per minute should be totalized by a counter (CTU).
    The obvious issue is, if the signal is "always" on, every minute when the reading check will be performed, there will be no rising edge per scan cycle to increase the counter up, namely no change in the PLC's input image.
    Therefore I had thought of using a cyclic bit in series with the signal. The cyclic bit should be set from off to on every time the task is executed....but I haven't found so far cycle bits as I know it from Siemens PLCs.
    My second attempt was to initialize a bool variable to TRUE at the beginning of the task and set it to FALSE at the end of it. But I can't manage to make it work together with the FB in charge of counting up the pulses ( related to this: l viewtopic.php?f=11&t=10030 l )

    How do you perform operations with counters implemented on cyclic tasks for steady signals as the one described?
    Thanks for your hints!
    Rob

     
  • i-campbell

    i-campbell - 2019-10-03

    I usually use the ADD instruction for "count up every time this is called."
    Sounds like you are using ladder?
    Add a box with EN/ENO and I think in Codesys it is ADD, it could be +
    Your first input is Count, second input 1, output is Count.
    Count is a variable of data type DINT.
    Next step, how to reset your counter.

     
  • Rob - 2019-10-03

    I-Campbell hat geschrieben:
    Sounds like you are using ladder?

    Indeed Iβ€˜m using ST....but I will go to the codesys online help and check the ADD function’s features
    Edit: ( ....the ADD function is in ST simply a:=a+1 ....of course. I will try this approach )

     
  • Rob - 2019-10-03

    It works like a charm now, thanks for your tip I-Campbell...this approach was quite simpler and more effective
    Still, I'm always into difficulties when trying to pack functions as CTU or Timers in FBs and/or its methods...as a beginner I have to invest more time into this...

     

Log in to post a comment.