08-29-2012 12:19 PM
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,
Matt
08-29-2012 01:18 PM - edited 08-29-2012 01:19 PM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-29-2012 01:49 PM
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..
08-29-2012 02:30 PM
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.
08-29-2012 03:51 PM
Take a look at what you're doing. The program is doing exactly what you're telling it to.
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-29-2012 03:55 PM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-29-2012 04:05 PM
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 )
Cheers
08-29-2012 04:13 PM
IK wens u goede bier, goede nacht en aangename dromen.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-30-2012 02:26 PM
Hi steve,
It did not work, or actually I mean.... I don't know how to..
ps: Het bier smaakte goed!
08-30-2012 03:06 PM - edited 08-30-2012 03:07 PM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks