LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to file when value is stabilized

Hello all,

 

I have the following problem which I can't solve myself.. My vi generates some data, the capacity of the capacitor, what I want to write to a text file. This must be only the stabilized value. Now it writes all data from 0 till 50 for example, and I want only the data when it's stabilized. I have some attachments to make all clear what I mean.

Is this possible to do?

 

Best regards,

MattNaamloos.jpg

Download All
0 Kudos
Message 1 of 11
(2,947 Views)

The VI doesn't look like the picture you attached.

 

If you want to write a value only IF some condition is true, you need a CASE structure.

 

See the attached VI.

 

Run it and flip the GO switch. It simulates a capacitor charging.

 

It uses Shift registers to remember the previous value, and compares each new value with the previous.

When the difference is less than a tolerance (beware of looking for zero difference), it Resets itself.

 

Put your WRITE TO FILE code inside that inner CASE and that's what you want.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 11
(2,937 Views)

Thanks Steve! I try to implement in into my VI. The picture is only a small part of the VI. And a few parts are missing, uploaded an older version accidentally..

0 Kudos
Message 3 of 11
(2,928 Views)

It is working, but only when  "append to file" is false on the "write to speadsheet file". When I put this on TRUE then I get a whole list like in the .txt attachment. And I want to do several measurements to calculate the mean value.. Any idea how come? This time I attach the correct VI.

0 Kudos
Message 4 of 11
(2,919 Views)

Take a look at what you're doing.  The program is doing exactly what you're telling it to.

 

Screen shot 2012-08-29 at 4.46.37 PM.png

 

You're telling it to append to the file anytime the difference between one sample and the previous sample is less than the tolerance.

If you want it to only write the stable value once, you've got to tell it that.

My example captured the stable value and turned itself OFF.  You've got to have another flag that stands for "I have written this value to the file already".  It starts out as FALSE.  You don't care aboutthe stability (don't write, or even compare) if this flag is TRUE.  When you write, you set it to TRUE.  You need something to reset it - a button click or something.  

 

The GO switch in my example did this - you can use a STABLE light or something similar, or maybe another ShiftReg.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 5 of 11
(2,907 Views)

Another trick you can use to avoid having another variable is to have an indicator of the numeric value.

 

Set it to zero when you start.

When the value becomes stable

   If the indicator is ZERO

       Set the indicator to the stable value

       Write Stable value to file

   end if

 

It amounts to using the indicator's value as a boolean - it's zero or it isn't, so I write, or I don't.

 

Just a thought.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 11
(2,904 Views)

Thanks a lot Steve for your reply. I will give it a try tommorow, 10 hours Labview a day is enough for me.. And over here in the Netherlands it is 11 PM. Beer and bed.

I reply tommorow (If it's not working Smiley Wink)

Cheers

0 Kudos
Message 7 of 11
(2,901 Views)

IK wens u goede bier, goede nacht en aangename dromen.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 11
(2,899 Views)

Hi steve,

 

It did not work, or actually I mean.... I don't know how to..Smiley Sad

 

ps: Het bier smaakte goed!

 

0 Kudos
Message 9 of 11
(2,870 Views)

Think about exactly what you want to do (writing it down helps for me).

 

You're running in a loop, measuring something every time thru.

 

You want to write ONE value to a file, but only after it's become stable.

 

You've already got the part about how to figure out if it's stable.

 

If you want to only write it ONCE, then you could quit the program once it's stable and you write one line.

 

Or you keep the program running, and keep some sort of variable that tells you that you have or have not written the value to the file yet.

 

You ONLY do the comparison if the variable is that you have not written the file yet (if you've already written the value, you don't care).

 

Once you become stable and write the file, set the variable to ALREADY WRITTEN.

 

You could use a boolean in a ShiftReg and use FALSE = NOT WRITTEN and TRUE = ALREADY WRITTEN.

 

You could use a boolean indicator on the front panel, where FALSE = NOT WRITTEN and TRUE = ALREADY WRITTEN.

 

You could use a numeric indicator on the front panel, where 0.0 = NOT WRITTEN, and non-Zero - ALREADY WRITTEN.

 

You need some other method of reseting the variable to NOT WRITTEN.  Maybe another button you click.

 

Or you could reset the variable to NOT written if the value becomes UNSTABLE again. (I don't know how you're testing things). That could work easy enough, but I don't know if it fits your test plan.  If you plugged in a capacitor, it would write a line when the value was stable.  Then when you unpligged it, it would write a value when it stabilized on zero, or whatever.

 

Study the VI I gave you carefully.  Understand how it displays ONE AND ONLY ONE value when becoming stable.

 

 

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 10 of 11
(2,864 Views)