I have the following vi that I am using as a subvi. The goal of the vi is to calculate the the count on ch A between during a period of the index. The vi works well most of the time, but on occasion the count given is 0. It seems to happen at random intervals as well. You can run the same test and one time it gives the correct count and then the next test it will give a count of 0. Is there anything glaring wrong in the vi that may be causing the error that I am just overlooking?
Your second loop has a couple of uninitialized shift registers. So they will use the last value from the previous run. From what I can gather, that is not desired.
I've tried setting those shift registers to 0 and it will still throw out a 0 count every so often.
Your post is insufficient to tell what you did, what you expect to happen, and what happen instead.
What is the program supposed to do? I seem quite a few questionable code constructs that could be simplified and streamlined.
What are typical input values for the various controls? It would help if you could fill reasonable default values before posting here so we have something that is ready to run.
Here is the VI with them initialized to 0. Just create a constant 0. Pretty much the standard way to set them to 0.
I guess output is the better terminology than throw out. Just meaning the "Count Test" output is 0 instead of the correct count.
There is no pattern of occurrence, and as far as I can tell it is truly random. It can happen once out of 50 runs, then 4 times in a row, then every other, and a so on.
The VI Execution Settings shows the settings for the subVI.
The purpose of the subVI is just to count how many rising edges happen during one revolution.
It still would really help to have some typical default values in the controls.
What is the meaning of the data in the "index" array"?
What is he meaning of the data in "Ch A"?
(In the first loop you could use a conditional tunnel. Index array is resizeable but if you would take element 1 and 2, you would not need to delete element 0 from array. You only look at two elements from the first loop. What if there are more (or less)? Shouldn't most of the second loop and the output be blue (integer)?)
The index array is the data from a hall effect sensor. It will be 0 expect for when the index on the magnet passes by causing it to be high, which is 5V.
Ch A is the data from Ch A of an encoder, so just a square wave from 0-5V.
The reason for only getting two elements from the first loop, is that gives you the length of that rotation. The count only needs to be calculated once per test, but it needs to be over an entire revolution. Any farther index pulses can be ignored for the purpose of calculating the count value.
I'm with Christian, your VI seems overly complicated. For instance, move your Greater Than to be before the loop. This will make things simpler inside of the loops. And then you can use a Greater Than to compare the current value to the previous.
With the same data set, I have yet to see a 0 come through.
EDIT: I just noticed that those Boolean constants should be set to TRUE.