LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why won't my formula node work?

I have the following code in a formula node.
if(x = 10E-9)
y = 0;
if(x = 10E-6)
y = 1;
if(x = 10E-3)
y = 2;
if(x = 1)
y = 3;
It is used to write the Current units to an Excel file for reading later. It seems to follow the code in the help file, but it always returns a 3. Why is this? I will also include the program it is used in. The program is meant to take an IV resistance curve for various samples. The program works, except for the formula node.

Also, f this doesn't work, is there a way I can increase the digits that Excel will read through Labview. When it is supposed to be reading 10E-9 Amps, it comes out in the Excel file as 0. This is problematic.
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 1 of 7
(2,991 Views)
You syntax is incorrect. The "=" should be "==". What you're doing is an assignment, which is always true, so each of your if statements is being executed.

A better way is to use an enum which you can then format directly into a string using the Format into String function, like this:




<added>

After looking at your code some more, a few points:

(1) Use the error clusters to establish data dependency flow. You can eliminate all of your sequence frames this way.
(2) Why are you using local variables to access front panel controls? Just wire to the terminals. You're just creating more memory usage.
(3) If you switch to the enum for the above you can simply have an array with the corresponding values that you can index to get the value to feed to your arithmetic.

Message Edited by smercurio_fc on 03-27-200601:13 PM

0 Kudos
Message 2 of 7
(2,984 Views)

Hi john,

i made the necessary changes for your Vi to run as you want.

you can just directly input the value from the control to the case structure. You just need to check the sequential values in the Edit item in properties of the control, so it will treat each value and assign them index. As nA as 0, microA as 1 and so on so now you can directly use it as an input to the case structure and the following current value will be an output

See the attached modified Vi

Regards,

Nitin

0 Kudos
Message 3 of 7
(2,973 Views)
npai:
your modification will break the VI, because the value of the control is used elsewhere via local variables.
 
JohnGalt:
You could just take the log (base 10) of the value and then make cases for 0, -3, -6, and -9. Attached example (LabVIEW 7.0) shows one possibility.
 
Some general comments (as implemented in my modification).
  1. There is no reason to make the "units of I" control EXT (extendend precision). Keep it a DBL.
  2. I don't think the user should be able to change the values during runtime, so the terminals should go outside the FOR loop.
  3. Avoid all these sequence structures. They hide code and make the VI hard to debug. You can fully define execution order using the error cluster of the VISA functions. Think dataflow!
  4. Avoid all these local variables.
  5. Don't forget to close the file when done.
  6. Do the string cocatenation outside the case structure to avoid all that duplicate code. Code that is identical in all cases must go outside the case structure.

Additional suggestions:

  1. You might want to replace the FOR loop with a WHILE loop so you can stop (1) on error or (2) when the desired number of iterations have completed or (3) if the user want to abort.
  2. Depending on how fast this loop runs, place an indicator in the iteration terminal so the user can monitor the progress.
  3. ...

My example is just a quick draft, please verify correct operation and modify as required.

 
0 Kudos
Message 4 of 7
(2,957 Views)

thanks altenbach,

I didnt go thru the whole Vi so check whether the value was recalled as a local variable in the program.

Regards

0 Kudos
Message 5 of 7
(2,948 Views)
This is another reason why local variables should be avoided unless absolutely necessary. Mistakes like this can occur easily when the VI is peppered with locals. 😞
 
No harm done, since JohnGalt apparently only has LabVIEW 7.0 and you posted in version 8. 😄
0 Kudos
Message 6 of 7
(2,938 Views)
Thanks all. altenbach's program seems to work. Now I just need to modify it for a Hall Effect Experiment, but that should be easy. I just need to loop this 12 times, with the switching card changing. Yes, I do only have Labview 7.0. Thanks for noticing, altenbach 🙂
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 7 of 7
(2,916 Views)