LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While Loop with Reading in from Text File - Timing Events in a Given Period

Solved!
Go to solution

Hi everyone.

 

I'm creating a program that interfaces via serial port to a syringe pump in my lab. Currently, the program reads in flow rate values from a text file and sends them to the pump one by one via various commands. I need to ensure that each time a new flow rate value is sent to the pump, it does so within a specific time frame/lasts for a specific time. I.e. every 0.1 seconds the flow rate changes and must last until the next period. I tried using a timed loop and I believe I succeeded, but it hogs the system resources so I was wondering if there was a way to do this using the tick count or something of that nature. I've just started using LabView so I'm slowly getting the hang of it (easy when you look at my VI!)

 

See attached VI. I took out the serial port commands and instead have the commands displaying in an indicator. The most nested and densely populated while loop contains the commands that must be completed/last for the given period (like 0.1 seconds).

 

Thanks for your time and help!

 

-Phebotalus

0 Kudos
Message 1 of 9
(3,567 Views)

Hi,

 

Maybe you could post the version of the file with the VISA commands.  I did a block diagram sweep and the application is not clear what you are trying to do.

 

You could always use a tick counter, but the way you program is going to determine what actually happens.

 

If you want to send a command every 10ms then you can't have the program doing a lot of other activities in parallel.

 

You could try having a wait inside the inner for loop to wait for 10MS after sending the command.  You could also set up a time stamp before and after each loop to measure your loop rate, if you are going long you will know.

 

In the inner case structure you have a race condition between the two writes to the local variable ( a.k.a. VISA write?)

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 9
(3,564 Views)

Hi,


Try this.  I put in a tick timer and re-did how you pull the first column of each row by using indexing.

 

 

-------
Mark Ramsdale
-------
0 Kudos
Message 3 of 9
(3,556 Views)

Hi Mark, thanks for replying so quickly Smiley Happy

 

The VISA command version is much older since without hooking it up to my lab computer I was always getting errors. At first I tried a wait, but I was told the counter begins after all commands in the loop execute once. While writing this I realized perhaps this might be an applicable solution since sending the flow rate command to the VISA port is the last command the loop executes, so if it waited the correct time then the iterations would work, minus a bit of lag in sending the new flow rate after the current iteration.

 

I'm not sure what you mean by a "race condition". Could you explain?

 

Also, I'm running LabView 2010, can you save an older version of the file you uploaded so I can read it?

 

Thanks!

0 Kudos
Message 4 of 9
(3,551 Views)

LV2010

 

Race condition, you are writing to the same local variable in the same structure, so you don't know for certain which write will happen first.  This may be important, not sure.

-------
Mark Ramsdale
-------
0 Kudos
Message 5 of 9
(3,548 Views)

Hey Mark.

 

So when I ran LabView and watched the data flow using the Highlight Execution, it sent the mode i command before the rate i command, which is necessary. If you don't think this is trust worthy, what's the best way to make sure one is sent before the other, but they are both sent when the true or false condition is fulfilled (with a postive or negative flow rate, respectively).

 

Can you explain the ticks passing and all that? I can't really follow it. As well why you chose 10 ticks and what means in ms along with the wait command. Timing is quite essential in the application so knowing the overall timing is important and how to get it.

 

You also mention moving the emergency stop command into the "data flow". What do you mean by this?

 

As well, what does the label "Use ofr DataFlow" mean?

 

Sorry for all the questions I'm just really trying to understand how everything comes together, slowly but surely!

0 Kudos
Message 6 of 9
(3,524 Views)

Also: To get the send commands in order, I used a flat sequence structure to make sure they execute at the proper times.

0 Kudos
Message 7 of 9
(3,506 Views)
Solution
Accepted by topic author Phebotalus

Hi,  You should read some of the introductory material on LabVIEW to get the dataflow idea down.

 

Basically the data flows in the wires from left to right, and any node will not run until all it's inputs has reached it.

 

The error wire is the best way to enforce data flow.

 

***

 

In your VI I am using data wires, running them through structures, and that forces the structures to run in order.  Using a sequence structure as you mentioned in your next post will force the two writes to run in order ( the one's we have been discussing to be in race condition.

 

Similarly, for brevity I would wrap the EMO and it's case structure in a single sequence and force it to run last using data flow.  That way the user has the most possible time to decide to hit the EMO before it is polled by the application.  As it is now, it most likely is polled at the start of the loop, so if it's value changes you will not see the results till the next loop.

 

When running in highlight execution you see the order of data flow, but that is not guaranteed to be the same for normal execution, hence the use of data flow.

 

***

 

The tick counter counts ms up to a really large number and then "turns over" back to zero and starts counting again.  My understanding is you want to START the loop as close to every 10 ms.  So, using data flow, take the tick count first, perform actions, then take the tick count again.   The second tick time read you are in a nested loop that doesn't end till you get 10 or greater difference on the tick count. 

 

And, in the off chance you should hit the "turn over" on the tick counter just stop the nested loop and move on.  ( if the second measure is lower than the first then the tick counter has turned over.  If you miss this situation then you would have to wait a long time for the condition of the difference >10 to be meet again, basically locked in the loop.

 

***

 

You could put the EMO sequence, discussed above, in line with data flow.  Before or after the second tick check won't make much difference in terms of 10ms.  I would put it after the tick check, again giving the user the most time to hit the EMO if needed.

 

***

 

I put in an error line for data flow and removed the other stuff. 

 

LV2010 

 

 Check out some of the intro LabVIEW docs, they are online, they discuss these issues and more.

-------
Mark Ramsdale
-------
Message 8 of 9
(3,498 Views)

Hey Mark read and did the tutorials on the NI website, just again, a lot to learn. I got the sense of data flow left to right, but not that it would follow it strictly. Good to know re: error wire and also how highlight execution works.

 

For the loop, I want it to begin at whatever number represents an origin of 0 seconds, and during the period (100ms) the commands are sent to the pump at the beginning and this continues until the 100ms timing is reached, at which point the cycle repeat. 

 

For the tick count I was confused if of the numbers and possibilities of turn over but your solution seems to have addressed that and also now I understand it counts in ms.

 

 

Mainly I find it difficult to understand some of the LabView literature at times, especially when it gets to more advanced functions as it assumes familiarity with a great deal of items. But thank you for all your explanation and help. I'm going to wire up the serial port commands and try this out in the lab tomorrow when I get my hands on the equipment 🙂

0 Kudos
Message 9 of 9
(3,481 Views)