From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

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
(2,843 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 LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(2,822 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
(2,797 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. 

 


GCentral
0 Kudos
Message 4 of 6
(2,795 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
(2,742 Views)

Just in case the base courses where skipped:

0-15 Counter.png

0 Kudos
Message 6 of 6
(2,605 Views)