LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I write to file at a discrete time step?

Solved!
Go to solution

I'm writing some variables out to a binary file in real-time (xpos, ypos, elapsed time) with a while loop (see blockdiag.png).  I'm using the time recorded by LabVIEW with an external devices clock to interpolate position values, before you ask, I don't have access to the external clock so interpolation is necessary after the data has been collected.  Currently, the while loop is unabated and runs as fast as the CPU will let it. After I'm done collecting my data, I plotted up the elapsed time in MATLAB and noticed some very strange behavior, negative time (see clocks.png)!!!! The black data here is my external devices clock and the red data represents the elapsed time written out by LabVIEW.  There are two instances in the vector that indicate a large negative step in time.  This doesn't always happen and seems to occur somewhat spontaneously within the elapsed time vector.

 

Questions:

 

1) Has anyone seen this behavior before?

2) Would putting a Wait.vi in the while loop help? (I figured this would at least regularize the time step.)

3) Please help.

 

Much thanks, please don't judge my LabVIEW code (I'm sure there are better ways to do it, but it works and that is how I want it).

 

Adam

Download All
0 Kudos
Message 1 of 14
(3,664 Views)

Hi AdamBlues,

 

To clarify, you said you are writing in real-time. Are you using the Real-Time module?

 

It is good practice to put a wait in your while loop. This frees up the processor to address other tasks.

 

This odd behavior may be because of a race condition due to the local variables. Where in your program are you graphing the clocks? Also, where is the start time variable being written? Finally, do the discontinuities always occur at the same place?

 

Best Regards,

Catherine B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 14
(3,590 Views)

I'm not using a Real-Time module, I don't think.  I actually don't know what that is.  Could you please give me some more information on that?

 

I put a wait in the while loop and still had the problem.

 

I am not graphing the clocks anywhere in the program, I don't really need to see them.  The start time is written in the previous frame of a flat sequence structure.  The discontinuities do not occur in the same place. Sometimes there is one, sometimes two, have never seen more than two.

 

Thank you for your response. I hope we can get this figured out.

 

Adam

0 Kudos
Message 3 of 14
(3,586 Views)

The Real-Time module is an add-on to LabVIEW that is used to interface with our Real-Time operating systems and hardware. Since you had mentioned real-time, I just wanted to clarify so we could be on the same page. More information about the Real-Time module can be found at the link below:

 

https://decibel.ni.com/content/docs/DOC-23701

  

Can you post your full code (project files and VIs in a zip folder)? It is difficult to get a full picture of what is going on from the snapshot you included in your initial post.

 

 

Thanks,

Catherine B.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 14
(3,559 Views)

 

I am guessing writing to disk is causing your timing errors

 

You might want to consider a producer-consumer program architecture in this instance.

 

That will allow the acquisition to be independent of writing to disk

========================
=== Engineer Ambiguously ===
========================
Message 5 of 14
(3,532 Views)

I think what you are suggesting is that I just store all the data into an array during acquisition and then write it out at the end?  I'm fairly certain I tried this once and I had a huge slow down when the arrays got large. They could potentially have about 1e6 elements in some cases.

 

Adam

0 Kudos
Message 6 of 14
(3,498 Views)

Here is a couple versions of my .vi.  I got an error when trying to save as LabView 8.0, so hopefully you have the more recent version.

 

Thanks for all your help.

 

Adam

Download All
0 Kudos
Message 7 of 14
(3,495 Views)

@AdamBlues wrote:

I think what you are suggesting is that I just store all the data into an array during acquisition and then write it out at the end?  I'm fairly certain I tried this once and I had a huge slow down when the arrays got large. They could potentially have about 1e6 elements in some cases.

 

Adam


If you are refering to my suggestion of a Producer Consumer archetecture, then no that is not what PC does.

 

Simple explainition a PC has a fast running aquisition loop (producer) that puts the data put into a Queue

 

Then a consumer loop dequeues the data and saves to a file.

 

Using a queue allows the Producer to get ahead of the Consumer without losing any data.

 

 

========================
=== Engineer Ambiguously ===
========================
Message 8 of 14
(3,486 Views)

@AdamBlues wrote:

 

Much thanks, please don't judge my LabVIEW code (I'm sure there are better ways to do it, but it works and that is how I want it).

 

Adam


I just wanted to make a brief comment regarding the above statement. I would recommend that you be open to changes to your code. There are many VERY experienced LabVIEW developers on these forum and there is always an opportunity to learn and improve your code. Just because something works doesn't mean that the code can't be improved dramatically. You may find that being open to suggestion will result in you becoming a better programmer and that your applications are more stable, robust and easier to maintain. For example, more often that not you are much better office using a state machine to replace a flat sequence structure. Learn how to use dataflow properly and the need for sequence structures generally disappears. These are just a few things that can be done.

 

I guess my point is that it is a good idea to try and remain open above suggestions to improve or change your code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 14
(3,481 Views)
I'm totally open to changes to my code, obviously it isn't working right. I just wanted to add a disclaimer here because I've been subjected to some verbal abuse in this forum about my code before, and it wasn't constructive criticism by any means. Thanks for the advice.

Best regards,
Adam
0 Kudos
Message 10 of 14
(3,473 Views)