Sequence not working as expected

Hello, I have an interesting issue with a sequence I’ve made in ladder. It’s supposed to be really straight forward. Starts at 0, once a user flips a switch, it’ll start counting up. Once it reaches a desired number, it’ll count down and then stop at 0. My issue is that it never stops at 0, just keeps going. Sequence numbers are as follows:
0: wait for user input → Seq 1
1: count up until reached a desired number → Seq 2
2: count down to 0 ->Seq 0
Interesting enough. Sequence 2 will go back to 1 without an issue, but never to 0.
Untitled Image

When testing the the equality of two real values you need to keep in mind that the values are stored in IEEE 754 format, so two numbers that look equal might turn out not to be when you look at them down to the last decimal place.
The general rule is to not test floating point numbers for equality, but rather “less than or equal to”, or “greater than or equal to”.
If you are adding and subtracting integers, like shown in your example, then changing the data type of all the variables to integer types will fix the comparison problem.

When testing the the equality of two real values you need to keep in mind that the values are stored in [IEEE 754</a> format, so two numbers that look equal might turn out not to be when you look at them down to the last decimal place.</p>The general rule is to not test floating point numbers for equality, but rather “less than or equal to”, or “greater than or equal to”.</p>If you are adding and subtracting integers, like shown in your example, then changing the data type of all the variables to integer types will fix the comparison problem.</p>

Thanks for the reply Martin,
I have tried changing it to “less than or equal to,” but unfortunately the result is still the same.

[https://forum.plcnext-community.net/discussion/comment/11479#Comment_11479</a></p>Thanks for the reply Martin, </p>I have tried changing it to “less than or equal to,” but unfortunately the result is still the same.</p>

Martin,
I suppose a correction is in order. It seems as using “less than or equal to” does indeed change the sequence number. But the logic keeps counting down even though the compare statement is now longer true. Can it be due to the connections between the block being dashed instead of a solid line? It’s been a while that I’ve worked with PLCnext, can’t recall seeing those. But I’ve noticed that the signal is “true” when the equality statement is true but “unknown” when it’s false.

Martin,
Here’s an updated snapshot of the ladder. The sequence does indeed change to 0. But, it then remains 0 no matter what and the subtraction function never stops.

Change Sequence 1. Make the EQ a GE, and swap the inputs. After that, it cycles through correctly.

Change Sequence 1. Make the EQ a GE, and swap the inputs. After that, it cycles through correctly.</p>[https://forum.plcnext-community.net/uploads/LEVPNBGNCUV0/image.png</a></p>

Thank you for your suggestion, unfortunately that did not fix the issue.

I believe it only “appears” to not go from 2 to 0.
Once the final rung is “true,” it moves “0” back into SEQ.
Once the scan repeats, your first rung is “true” and it is moving “1” back into SEQ. I don’t think you ever see “0” in SEQ because it immediately changes to 1.
Just an idea…
SFW

I believe it only “appears” to not go from 2 to 0.</p>Once the final rung is “true,” it moves “0” back into SEQ.</p>Once the scan repeats, your first rung is “true” and it is moving “1” back into SEQ. I don’t think you ever **_see </em></strong> “0” in SEQ because it immediately changes to 1.</p>Just an idea…</p>SFW</p>

The thing is, I am seeing 0 in my SEQ. After it counts down back to 0 it does indeed move 0 into SEQ. Which should de-energize the entire rung that contains the subtract function. But it doesn’t. So even with SEQ=0, the logic keeps counting down indefinitely. It also shouldn’t be moving 1 into SEQ until I enable “Apron_Go” so if it does, that a whole different issue I’d imagine.