LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code only works when I divide everything by 10?

Solved!
Go to solution

I've been working with the code below that is supposed to determine the best display value to use given an input (measured period) 

 

by10.png

 

I have no idea why, but it only works if I divide all my values by 10. Why is this happening?

0 Kudos
Message 1 of 6
(3,420 Views)

I do not understand what you are doing, but look at the items in your array, 1mV is 10000,  2 mV is 5000, ....  (Go to the ring properties and select edit items)

 

I am guessing that 1mV * 10000 = 10V 10x big,

2mV * 5000 = 10V 10x big, etc

 

mcduff

Message 2 of 6
(3,393 Views)

1. You did not wire your value through in the disabled case where you are doing the divide by 10.

2. Your first loop and logic before it can be replaced with a Max & Min and a Ramp Pattern VI.

3. A bunch of your calculations can be done before the FOR loop.

4. You could probably use the Threshold 1D Array instead of creating a potentially large Boolean array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 6
(3,374 Views)
Solution
Accepted by topic author ATE-EGNE

So I implemented the changes crossrulz talked about, and switched Insert Into Array for Build Array, and looked at 3 different methods for generating the boolean value in the loop.

 

In the second method, check if the Search 1D Array value is greater than or equal to 0. This just means it found a true value - there's no need to compare the double values again because you're making the same check. The behavior is the same as the original method.

 

In the third method, I used the Threshold 1D Array. In the case that the test voltage is too large, the return is equal to the size of the array minus 1, so I checked for output less than size of array - 1. However, the same value is returned when the test voltage is equal to the maximum (e.g. 3.2V). This triggers a failure to find a suitable range, which does not occur with methods 1 and 2 (the Search 1D Array methods). I'm not surprised that method 3 fails here, but I'm surprised the last boolean is true for 3.2<3.2. Presumably this is a double comparison issue.

 

vChoice.png


GCentral
Message 4 of 6
(3,366 Views)

Here is an alternative based purely on the outputs the OP currently has.  The idea is to just compare the largest V/div to the values and see which ones will not fit.  Do note that the Threshold 1D Array assumes a constantly rising slope in the array.  And in order to check that last value, I just add a Not A Number (NaN) to the end of the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 6
(3,336 Views)

Hey all! Thanks for the fantastic feedback! I've gone ahead and updated my vi with your suggestions. For more context, here it is in its subvi

 

by10rev.png

 

Since it's only passing a single Period  I think it's best to do the search as I have it now as cbutcher was saying that the Threshold 1D array was having issues with boundary conditions.

0 Kudos
Message 6 of 6
(3,300 Views)