LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

shift registers and while loop problem

Hi frens,
 
I got a problem here:
 
1. I want to continously operate a loop that compares SET power with MEASURED power:
    If SET = MEASURED power, loop stops.
       SET > MEASURED power, an increment of 1 will be added into existing hexadecimal string vice versa for SET < MEASURED.
   
So in the vi I have passed the string of hexadecimal code from previous loop via shift registers. Please help me check if I've done this procedure properly.
 
At present, this vi seems to be incrementing continously w/o stopping. Where is the problem?
 
Thanx alot.
KK 

Message Edited by kingkong on 04-25-2006 01:33 AM

0 Kudos
Message 1 of 11
(3,660 Views)

Hi Kong,

      Look carefully at the condition being used to stop the loop.  Do the values being compared change while the loop is running?

You're comparing two floats for equality, so even if "Set" and "Measured" agree to 14 decimal places, you'll keep looping.  Smiley Surprised  Use the "In Range and Coerce"  Function to terminate when values are close.

There's an uninitialized string shift-register which will have a value after the first run.  Subsequently, when you press run, control values will start with some (arbitrary) value. Smiley Wink  Give the left shift-register an initial value (empty-string.)

Cheers.

 

Message Edited by Dynamik on 04-25-2006 02:29 AM

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 2 of 11
(3,642 Views)
Yup, you're right!
 
But what if my SET and MEASURED are variables? Then how do I use the 'in range and coerce' function?  
 
From what I gather from this 'in range and coerce' function, I hafta set 2 fixed values for upper and lower limit.
 
How about if I use 'string subset' function to extract out the number of digits of precision I require and then compare them? 
 
Rgds,
KK
 
 
0 Kudos
Message 3 of 11
(3,622 Views)

You can make the upper limit

+Inf

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 11
(3,619 Views)

Sorry Ben, I dun quite get it.

If so, then how do I compare 2 values(which are variables) at 2 decimals place precision?  

0 Kudos
Message 5 of 11
(3,613 Views)

Please disregard my last.

its a typical pre-cafeine reply. Smiley Mad

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 11
(3,604 Views)
Just create the upper/lower limit based on one of the values that you're using in your comparison:

    upper limit = SET + 0.1
    lower limit = SET - 0.1

or whatever offset is appropriate for your application.

Message 7 of 11
(3,590 Views)
Hi friends,
 
Please have a look at the compare(testing).vi I created for comparing.
 
In this vi, 2 values(variables) are being compared and if both values are same, program stops. Else result is printed.  
 
Eg. SET power = 20.9333  Display = 20.9
       MEASURED power = 20.94 Display = 20.9
 
Result = SET > MEASURED
 
The above was input into the vi and it should take care of the comparing problem as mentioned by Dynamik earlier.
 
Am I right?
0 Kudos
Message 8 of 11
(3,567 Views)
Hi Dynamik,
 
Yes, the MEASURED value should always change as loop iterates. However when I debug, it stays constant => Hence my loop never stop incrementing!!
 
I have already ensured the points of precision for the values of MEASURED and SET, so it should only compare up to a decimal's place.
 
What should I do now?
 
Rgds,
KK

Message Edited by kingkong on 04-26-2006 05:42 AM

0 Kudos
Message 9 of 11
(3,538 Views)


@kingkong wrote:

What should I do now?


Answer: Follow the advice given on this board, which said to NOT use an equality operator when comparing floats. Period, end of story. I'm sorry to be so blunt and forceful, but you don't seem to be understanding this point. You're confusing value with display. Your control is set to display only one digit of resolution, but the underlying value doesn't change! It's irrelevant how you display it - it only matters what its value is. Bottom line: DO NOT USE THE EQUALITY OPERATOR TO COMPARE FLOATING POINT VALUES.
Message 10 of 11
(3,511 Views)