From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Design patterns for looping over multiple criteria in device test

Often in testing the device under test needs to be tested over multiple criteria (for example temperature, voltage, frequency, power, etc.).

 

The usual way to handle this is by nested for loops. This approach has its shortcomings, like complicated code and difficulty of adding a new loop into the nest.

 

Is there a better way, perhaps with a state machine implementation?

0 Kudos
Message 1 of 12
(2,578 Views)

Why would you need to add a new loop? Just iterate over an array of tests and add a new array element if needed.

 

Typically, we can give much better advice if we can see some code.

0 Kudos
Message 2 of 12
(2,550 Views)

@stephenb2 wrote:

The usual way to handle this is by nested for loops. This approach has its shortcomings, like complicated code and difficulty of adding a new loop into the nest.


Complicated compared to what and for who?  Inherently, more parameters tend to more complication.  It is really just a matter of how you want to configure your test to which route you want to take.  As Altenbach stated, you could just put all of your parameters inside of an array of clusters (each array element being a cluster for a specific test step) and then you just need 1 loop.  But this can get really complicated/tedious as a user to configure.


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
0 Kudos
Message 3 of 12
(2,531 Views)

@crossrulz wrote:
But this can get really complicated/tedious as a user to configure.

Since the OP was talking about "adding loops", I assumes the number (and order) of tests is a compile time decisions.

If these should be a runtime decision, things get a bit more complicated. You need to design a intuitive UI and scalable code (state machine), but that's certainly doable.

0 Kudos
Message 4 of 12
(2,525 Views)

@altenbach wrote:

Since the OP was talking about "adding loops", I assumes the number (and order) of tests is a compile time decisions.


It may be, but then the "user" configuring the tests is the OP.  And making arrays of clusters can get very tedious (been there).  Personally, I have never had an issue with nested loops, even when looping over several parameters.  Good use of subVIs alleviates most of the issues.


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
0 Kudos
Message 5 of 12
(2,519 Views)

Here is a picture describing the same thing.

 

my_test.PNG

 

Say I next find out that I need to add a loop for testing over voltage, keeping power as the innermost loop. I would need to create a new for loop and insert it at the correct nesting level.

 

What if there was a later requirement for additional loops (channel, modulation, bandwidth)?

I personally find this cumbersome and was wondering if there was a better solution.

0 Kudos
Message 6 of 12
(2,513 Views)

You are basically creating multiple degree of freedom testing plan.  It will grow exponentially larger.

 

I assume that if you have 5 temps, 4 frequencies, 3 powers, you want a combination of all those, so 5x4x3 tests = 60.   If you had another parameter like 4 channels, then it multiplies by 4 and now you are at 260.  If for some reason you say you only want to test 3 or 2 channels for some combinations of the original 3, the multi-loop idea will fall apart.

 

If you are the programmer and the test configuration person, then going to 6 or 7 or 8 loops like you showed won't be that hard.

 

If you want to flatten it to a single loop, then you need to create a flatter structure where you keep your various arrays, and pointers as to what the current test is.  As you increment through power, you increase the index by 1.  If you increment past the end of the array, then you reset it to 0 and increment frequencies by 1.   Likewise for the next level when going from frequency to temperature.   If you add a forth parameter, you don't need to add a loop, but you will need to add logic for how to increment through that new 4th array.

 

It might be just a bit easier to go to N test with that structure than the nested For Loops, but still may be tough.

 

You may just want to create a recipe of tests in an external application such as Excel where you quickly tabulate all combinations in a list, export it to a CSV file, and let LabVIEW read it in.  Just iterate through the list line by line feeding the various parameters into the center subVI.

0 Kudos
Message 7 of 12
(2,501 Views)

@stephenb2 wrote:

Often in testing the device under test needs to be tested over multiple criteria (for example temperature, voltage, frequency, power, etc.).

 

The usual way to handle this is by nested for loops. This approach has its shortcomings, like complicated code and difficulty of adding a new loop into the nest.

 

Is there a better way, perhaps with a state machine implementation?


Yes there is a better way and you answered your own question. (State Machine)

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 12
(2,497 Views)

@stephenb2 wrote:

 

my_test.PNG

 

Say I next find out that I need to add a loop for testing over voltage, keeping power as the innermost loop.


 

All you need is a single FOR loop with N wired as the product of all array input sizes. From [i], you can easily calculate the unique indices for each (now no longer autoidenxing) arrays to do your test.

0 Kudos
Message 9 of 12
(2,493 Views)

Here is a single loop implementation. I need to think about a state machine some more ...

single loop.png

0 Kudos
Message 10 of 12
(2,420 Views)