# LabVIEW

cancel
Showing results for
Did you mean:

## Can the Count be reset within a while loop

I am trying to write a device control routine
I want to control an external spectrometer through COM1 and get data back through a NI USB-6008 DQ
I need to do this in 2 ways, 1. manually - set the controls individually for each reading and 2. with an automated sweep, between specified values.
The front panel should only have 1 graph for each method.

I have attached code to show how I've approached this problem.

The bit I'm stuck on, is that when the automated sweep is initaited it need to reset the loop count to control the drive frequency, but I cant find out how to accomplish this.

any help would be appreciated
Message 1 of 7
(5,772 Views)

## Re: Can the Count be reset within a while loop

While you can't reset the output of the iteration terminal in the while loop you can easily program your own counter. Just use a shift register initialized to zero and add 1 to it each time you need to increment. Reset it at the beginning of each sweep. You will have to add the logic so that it knows when to reset the counter.
Message 2 of 7
(5,765 Views)

## Re: Can the Count be reset within a while loop

Hi,

I needed something like this, (triggers that repeat at regular sub iterations through a loop).    Thinking in hexadecimal with bits all high, here is an example that produces a true on every 7th and 15th (#F) loop iteration:

Message 3 of 7
(177 Views)

## Re: Can the Count be reset within a while loop

Tom,

Not sure why you posted to a 16 year old thread - which seemed only partially relevant to what you were demonstrating.  Your prerogative.

But I did want to make sure you realized that the code you posted doesn't do what you labeled it as, strictly speaking.  Your Boolean outputs from your "Equals?" nodes will actually be TRUE every 8 iterations, and every 16 iterations.  As you think of the loop iterator in binary, the LSBs 111b and 1111b will occur every 8 and 16 patterns respectively (NOT every 7 and 15!), and they'll be coincident when the 16th pattern occurs.

Below is a snippet that shows one way to get either set of behaviors, demonstrating the distinction, since I wasn't certain which behavior you actually wanted (every 7th and 15th, or every 16th on the 0x7 and 0xF cases).  It's certainly not the only way, but for these sorts of things I use the quotient & remainder (modulo) node, it makes intent clear IMO.

Best regards,

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 4 of 7
(162 Views)

## Re: Can the Count be reset within a while loop

Since this thread has been resurrected...

I prefer using a shift register to keep my counts.  I got into this habit from doing FPGA, where the loop iterator will max out fairly quickly.  On Windows, it is easy to just use the Quotient & Remainder to reset the count.  But that is really expensive on an FPGA.  So I use a Select function to reset the count instead.

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 7
(155 Views)

## Re: Can the Count be reset within a while loop

Hi Dave,

The good news is, this isn't a 16 year old thread any more! LOL!

To answer your query as to why I posted to such an old thread, these threads are brand new to many, (like me) who searched on this subject recently.  With that in mind, I think it is our duty to share kindly with the community when we solve an issue.

Sometimes people might want to clear the count because they want a trigger on a subset of the main loop.  If not, then my simple solution isn't appropriate for them.

I definitely should have clarified my statement on the 7th and 15th count which includes the 0th count or first loop iteration.

I'm giving you a kudos for that one Dave!

Blessings,

Tom

Message 6 of 7
(149 Views)

## Re: Can the Count be reset within a while loop

@John Rich wrote:
While you can't reset the output of the iteration terminal in the while loop ...

Of course you can reset the iterator.

Stop the loop. Restart it. Note that the iterator is reset. 😎

Of course utilizing this results in rather silly code, it is a fact. Usually this results in questions like: " How can I keep my count if my loop stopped".

Message 7 of 7
(114 Views)