09-10-2015 04:44 AM - edited 09-10-2015 05:00 AM
Hi,
A test system that deteced if a connection is good or NC in a cable. (This is only a SubVI of my complete system)
1. When it goes in my case structure "Connection Approved" is should run my for loop "Counter Setup", where it counts a ilteration up for every time the digital signal goes low. (Works fine)
2 When it goes in case structure "Connection NC", it should not been using my "Counter Setup" but save the value of my local variabel "Total # cycles" + the elapsed time in a txt file.
Aboved should happend the first time it goes NC and only should 1 value or max. 10 ilteration afterwards where it is NC.
It works alright, but when I hit my "NC when lights on"-button it stops every 20 ilteration. Ex. if i press the button at cycle number 12, it will run until it reach 20 and the stop.
Same procedure if I hit the button on ex. 24 it will first stop at ilteration number 40. Why is this and how to fix it?
Also my "Elasped time" only runs continuously when it is NC. If connection is good it olny update the time every 20 ilteration.. Again why so slow and how to fix it?
I will also like if the text file where as simple but with my two data listed nicely (# cycle, Elapsed time). At this moment it save way to many ilteration in the txt file.
And please let my now how else that I could optimaize this code 🙂
Thanks in advance.
I attached a snippet and my txt file.
09-10-2015 05:43 AM
Hi anja,
it's all in THINK DATAFLOW!
1. When it goes in my case structure "Connection Approved" is should run my for loop "Counter Setup", where it counts a ilteration up for every time the digital signal goes low. (Works fine)
Why is the iteration count of your FOR loop depended of the string length of "Conn. Approved"? (Atleast it seems so.) Doesn't seem to make sense to me…
Why do you use so many local variables of "total # cycles"? Why not use a shift register instead (as it should be)? Why have the terminal of that indicator unwired?
2 When it goes in case structure "Connection NC", it should not been using my "Counter Setup" but save the value of my local variabel "Total # cycles" + the elapsed time in a txt file.
You always write "total # cycles" in your measurement file. Always as there is no condition applied!
When you want to save data in the file only under certain conditions you need to use a case structure - around your WriteData function! (This is very basic programming, independent from LabVIEW.)
but when I hit my "NC when lights on"-button it stops every 20 ilteration.
Nope.
It does not stop. Your WHILE loop only stops when you hit that unlabelled button. (Two notes: never delete/hide labels in the block diagram. Use left-to-right wiring, StyleGuide helps to read your block diagram!)
It seems every 20th iteration may take longer to execute - I cannot open your VI and so I'm not able to examine your DAQAssistent…
Btw: why do you read an array of data from DAQAssistent and only use the very first sample?
Also my "Elasped time" only runs continuously when it is NC. If connection is good it olny update the time every 20 ilteration.. Again why so slow and how to fix it?
Wrong. Your "Elapsed Time" indicator will update in EACH iteration of your WHILE loop.
Maybe the WHILE loop takes longer to execute each 20th iteration?
09-10-2015 05:44 AM
1. You really should learn to use Shift Registers instead of using the local variables. It will make things easier and force you to use proper data flow.
2. Why don't you just put the FOR loop inside of the case structure? That would make a lot more sense.
3. Actually, why even have a FOR loop? When you have a Connection Approved, that loop will run 21 times before another write to your file. Is that really desired?
09-10-2015 05:46 AM
@GerdW wrote:
Maybe the WHILE loop takes longer to execute each 20th iteration?
I think it is more like it takes 20 iterations of that FOR loop before the next update is actually done. That outter FOR loop should not be there.
09-10-2015 06:57 AM
Thank you both for the answers, appreicate it!
I should have mention, that i pretty new to LabView, so i try to absorb and corret you suggestions - but takes a little time 🙂
Why is the iteration count of your FOR loop depended of the string length of "Conn. Approved"?
This Vi is just a snippet and a fragment, and the strings is to illustrate my condition for this case structure.
You always write "total # cycles" in your measurement file. Always as there is no condition applied!
When you want to save data in the file only under certain conditions you need to use a case structure - around your WriteData function!
Okey, but what should I do then? Not guite sure if you mean, that i should og should't use a case structure around my WriteData function to meet my wishes.
09-10-2015 07:00 AM
I moved my outter FOR loop inside my case structure in the right sceneraio. I works better now, but im afraid in my bigger system (which I haven't uploaded) will give some complications. But is't okey for now.
Yeah, i'm not that familiar with Shift register. I'll like to but i get confused that i'm only able to use them on my while loop? Could you give me some hits about shift register and how i should use them in my case?
Thanks for you eariler answers, I appriciate it.
09-10-2015 07:03 AM - edited 09-10-2015 07:03 AM
Hi Anja,
the strings is to illustrate my condition for this case structure.
The condition for this case structure is the button "NC when lights on", these strings are outputs of the case structure…
Don't mix up things!
Even when the VI is just a fragment it is very irritating to use the string length as a measure of how much data you want to aquire from DAQmx…
to meet my wishes.
Your wish is to write to a file, when a certain condition is met.
To check for a condition you need to use a case structure. All things, which should happen, when the condition is TRUE, need to be put into the TRUE case of this case structure. (Pretty basic programming, not related just to LabVIEW.)
Yes, you should put a case structure around your WriteData function…
09-10-2015 07:17 AM
Your wish is to write to a file, when a certain condition is met.
It already write the data i'll like to collect. But i kinda collect way to many data.
If it's disconnectet for ex. 30 sec it might type that out like 100 times in my txt file. I'll like even if it is disconnected for 60 sec only to write out 10 times that is has been disconnected at the specific cycles?
How do i comply with that?
09-10-2015 07:55 AM
08anja wrote:
Yeah, i'm not that familiar with Shift register. I'll like to but i get confused that i'm only able to use them on my while loop? Could you give me some hits about shift register and how i should use them in my case?
You can use shift registers on your FOR loops too. These are very basic, so I would recommend going through some free tutorials
3 Hour Introduction
6 Hour Introduction
LabVEW Basics
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Learning NI
Getting Started with NI Products