No announcement yet.

Detect any change in integer

  • Filter
  • Time
  • Show
Clear All
new posts

  • Detect any change in integer

    What is the best and most reliable way to monitor an integer value, and trigger an operation on the first scan (and only the first scan) following the change?

    Right now I'm using a compare contact which is configured as OLD_INT != CUR_INT then it outputs a boolean NEW_VALUE_FLAG as true.

    On the next line, I have NEW_VALUE_FLAG as an edge N/O contact, then perform the task I need along with updating OLD_INT to match CUR_INT.

    Hopefully that makes sense. I don't know how to put line logic in the forums.

    This appears to work, but I can't help thinking there might be a simpler way. Looking for other suggestions.

  • #2
    That's a pretty simple way to do it. You just need to reset NEW_VALUE_FLAG again after you use it.

    You could also use the compare to send a pulse output (for one scan) which will also reset as well as write new val into old val. Not all PLC's support a one-shot out.

    I wouldn't worry about it much unless you have a reason to save space. I'm a big fan of comments if you want to make something clear. I find that lacking a lot in many programs I struggle to troubleshoot.


    • #3
      my usual method
      When IntegerTag does not equal OldIntegerTag, make OldIntegerTag equal to IntegerTag and set ValueChangeFlag to true.
      On the next scan, IntegerTag WILL be equal to OldIntegerTag and therefore ValueChangeFlag acts as a oneshot --unless IntegerTag changes during a scan
      You can use the ValueChangedFlag to CALL a task or trigger ThatSpecialThing that you need done on the subsequent scan.

      .     IntegerTag      OldIntegerTag           | CPD
      .----------------]<>[-------------------------+ IntegerTag     OldIntegerTag
      .                                             | 1              ValueChangeFlag
      .                                             +------------------------------
      .            ValueChangeFlag                
      .----------------] [--------------------------[CALL   DoThatSpecialThing]