11-15-2017 11:14 AM
Hello,
I have noticed an apparent discrepancy when initializing a shift register for use in a while loop. The attached diagram illustrates the problem. A value of 0 is used (rather than the initial value of 5) unless I enable Highlight Execution.
The same issue exists in both LabVIEW 2016 and LabVIEW 2017.
Thanks,
David
Solved! Go to Solution.
11-15-2017 11:43 AM
I suspect what is happening is that the I32 overflows and gets replaced by a zero before you can notice. If you create an auto-indexing tunnel to see all the values stuffed into the shift register, you will see the sequence of outputs that leads to a result of zero by the time you stop the VI. Even with a 100ms wait it only takes about 4 seconds to occur, so with no wait it happens almost instantaenously.
5
10
30
120
600
3600
25200
201600
1814400
18144000
199584000
-1899959296
1070332928
2099759104
1431615488
1431011328
-1442611200
-197197824
548208640
-1920729088
-1680605184
1681391616
17301504
415236096
1790967808
-679477248
-1166016512
1711276032
-1912602624
-1543503872
-603979776
-2147483648
-2147483648
0
0
0
0
11-15-2017 01:08 PM
What you are trying to compute is basically a factorial:
5*(i+1)!
It's not the fact that the I32 overflows that is giving you a zero result. It actually starts overflowing after 12 iterations (i=12)
5*(12+1)! = 31135104000
[32bit integer -2147483648 to 2147483647]
But as i continues to increase, the LS bits of the shift register continue to fill with zeros. Eventually when i=33, all bits are zeros, and zero x anything = zero
You can see the effect better if you display the resulting array in binary.
11-15-2017 02:10 PM
Thanks for your reply. I agree that an overflow will occur, but that is not what I'm seeing. I modified the VI to prevent an overflow and ran it twice (once with execution highlighting disabled, and a second time with execution highlighting enabled. Here are the results in each case:
With execution highlighting disabled, the shift register does not initialize and the output value is always zero.
With execution highlighting enabled, the shift register is initialized to a value of 5 and the output value is eventually clipped at 1000000.
11-15-2017 02:17 PM - edited 11-15-2017 02:17 PM
The in-range and coerce does not change anything from the others have said. When it overflows, it coerces the value to zero and ...
Mod your code to stop after five iterations.
Ben
11-15-2017 04:47 PM
You know, I have to admit that I just had a similar issue where I was raising an integer to a power and couldn't understand why sometimes the answer was incorrect. Turns out that sometimes the resulting number was larger than the datatype could handle. So I coerced the original number to a larger datatype so the resulting calculation would also use that datatype. Yikes.
11-16-2017 09:02 AM
If you want to verify that your shift register is being initialized to 5, you can add a Wait (ms) function to your while loop. This will slow down the execution. You can then probe the wire coming out of the shift register and watch the value of that wire increase. By slowing down the while loop using the Wait (ms) function you won't need to turn on highlight execution. I have attached screenshot below as well as my VI.