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

How to access the value of a variable held in the previous cycle in ST?

pcs-1282
2021-08-31
2021-09-01
  • pcs-1282 - 2021-08-31

    Is it possible in CODESYS to access the value that a variable held in the previous cycle and compare it with it's present value? I am used to working with ABB's tool, which had the option of defining an attribute called STATE to a variable, which helps in accessing it's previous cycle value in the ST code. Thank you!

     
  • ph0010421 - 2021-08-31

    Changed := Old <> New;
    Old := New;

     
    • pcs-1282 - 2021-08-31

      Hi, pardon my ignorance, I am a bit new to this, but to compare the Old & New values, I would need to have access to them. My doubt is, for a particular variable, say X, how do I go about getting the value of X:Old (as in the value it held in the previous scan cycle)? Thank you!

       
  • i-campbell

    i-campbell - 2021-08-31

    therr is no special command for this, you would need create a new variable called "previous_x" and do
    previous_x := x;

     
    πŸ‘
    2
    • sean-barton - 2021-09-01

      Right, this is what I typically do to compare past and present values as well.

       

Log in to post a comment.