sp_

Working with rate of change and decimals in TIA portal

4 posts in this topic

I am working on a PLC program that requires an analog valve to close a given percentage in a given time in seconds. I give the start position, the final position, and the time. I calculate the rate of change and I add that to the start position every second until it reaches the final position. For example, the start position is 0%, the final position is 50%, time is 5s. So the rate of change = (50-0)/5 = 10%/s. So every second I add 10% to the current position of the valve until it equals the final position and then it stops. This becomes tricky when the rate of change has many decimals or a recurring decimal and using the equal to comparator. for example, the start position is 0%, the final position is 40%, time is 7s. the rate of change = (40-0)/9 = 4.444444...%/s. The current position is never exactly equal to the final position and the logic keeps executing infinitely and the valve is either fully open or fully closed. I have tried a few different things such as rounding the numbers or using limits instead of equal to, but none of it seems to be working perfectly.

Is there a better way to do this?

Thanks!

Share this post


Link to post
Share on other sites

Don't use == (Equal), use >= (Equal or greather than). When using REAL tags for that purpose, with Equal comparison, you run into problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now