LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Particular Problem with sweeping through a range of values using a while loop - please help.

Hi,

 

I'm pretty new to labview, I'd be grateful if someone could help me out on this one.

 

I'm trying to implement a voltage sweep, by providing a Start Point, Stop point and Step size. I've implemented it using a while loop, where basically a shift register adds on the step size to the start point and when the value equals the value of the Stop point the loop breaks and the program stops.

 

The attached VI seems to work with whole numbers e.g. Start 1, Stop 10 and Step Size of 1. However when I use a Start value of 0, Step of 0.1 and Stop of 1, the loop never breaks. Everything seems right logically. Could someone please explain why this is happening.

 

What I've also noticed is that if the equal to sign is changed to a greater than or equal to then the loop does stop at the required point.

 

I've attached the VI (IncrementStepSizeWhile.vi)

 

Many thanks.

0 Kudos
Message 1 of 3
(2,840 Views)

You might get better support if you posted LabView questions in the LabView forum; this is the LabWindows/CVI one. Having said that, from your description it sounds like a problem with accuracy and representation involving floating point operations. It is very rare for calculations with floating point numbers to produce exact round numbers - probably your loop variable is ending up as 1.000000000012657, which of course would fail the equality test to 1.0. Golden rule: never compare floating point values for equality. As you found, >= or <= is always preferred.

 

JR

0 Kudos
Message 2 of 3
(2,838 Views)

Many thanks JR, I'll also post this up on the Labview topic forum.

 

ranveerm

0 Kudos
Message 3 of 3
(2,830 Views)