LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I reset the i in the while loop to 0 after i=15 each iteration?

Hi members,

 

I want to ask how can I reset the i in the while loop to zero after i reach 15 in labview..

 

I want always to reset the i to zero after i reach 15.

 

your help will be highly appreciated

0 Kudos
Message 1 of 6
(1,448 Views)

Hi Tasnim,

 

you cannot reset the "i" (iteration counter) in the while loop.

 

But you could apply simple math on the value delivered by i: when you want to count up to 15 and then start again with zero (like a sawtooth pattern) then a simple modulo operation (using Quotient&Remainder) will be the solution!

Best regards,
GerdW


using LV2020 on Win8.1+cRIO
0 Kudos
Message 2 of 6
(1,427 Views)

@Tasnim wrote:

I want to ask how can I reset the i in the while loop to zero after i reach 15 in labview..

 

I want always to reset the i to zero after i reach 15.


0-15 can be done with an AND. I AND 15 will result in 0-15. On an FPGA, that will be much more efficient than a Q&R, that potentially requires multiple iterations.

 

On an FPGA, you'll also run into the problem that the i will reach it's max value pretty soon. You'll get that on a PC as well, but it can take a while... On and FPGA running at 40 MHz, the 31 bits become a problem after 53 seconds. IIRC, on FPGA, the i will stop at it's maximum value, on a PC it will wrap to the min value. Not sure...

 

I'd consider for a shift register for any code except the most trivial. Increment the value when approprieate, and use Q&R or AND to get the effect. This will be more flexible in the long run, as the behavior is decoupled from the loop counter.

 

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

If your loop runs extremely quickly (typically on FPGA) you might instead consider a Shift Register and a select node with equals 15 comparison. 

 


GCentralI'm attending the GLA Summit!
0 Kudos
Message 4 of 6
(1,400 Views)

I will also throw in my vote for keeping your count in a shift register.  As stated, only truly necessary if in an FPGA, but anything running a long time should use the shift register method instead of the iteration terminal.


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 6
(1,347 Views)

Just in case the base courses where skipped:

0-15 Counter.png

0 Kudos
Message 6 of 6
(1,210 Views)