LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What's wrong with this code?

Please help me. In the attached code, I need to be able to change my outgoing signal as a function of time. The Get Date/Time in Seconds.vi seems not to be accurate. It is not updating the local variable as I suspect it should to change the outgoing signal at the time that is required. What am I doing wrong?
0 Kudos
Message 1 of 6
(3,001 Views)
The basic problem is that the local variable (which you shouldn't be using in this case anyway) is being updated inside a loop, but it is only being read once--outside all the loops at the very beginning of execution.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 6
(3,001 Views)
Thanks, but what should I be doing instead? Won't the use of loops stall the program until the end of execution?
0 Kudos
Message 3 of 6
(3,001 Views)
For improved performance, you need to have the loop just aquire data. This means you will need to move the write to file which is slow outside of the while loop and just write all the data at once.

This transistions into the problem of how to build the array and this really depends on how you want to acquire data. If your sample size is small enough (you will have to do the math), you can have the ai read just read all the data and return one final array. This is the simplest method of all. If you want to do continious acquisition, you will need to build an array. There are two good methods. The best method is to create an array ahead of time with initilialize array, feed this into a shift register and write the data as it comes in
to the appropriate positions in the array. The other method is to use shift registers and the build array function to add the new data to the previous values. Be sure to right click on the build array and select concantenate.

The next concern is the time stamping. Bear in mind that your data is collected in regular intrevals so you can know the scan rate and the initial time so you know when all the samples were taken. Now you need to be concerned as to when the data acquisition is actually started. It is usually not important to know when exactly (greater precision that a ms) an acquistion started because the pc is a self contained acquistion system. If this information is important you need to consider using a trigger to start your scans.

Finally, you have a number of options to get the aboved mentioned data. AI start and AI read both have terminals that convey info. You also have the option to have the data presented in a number of ways. To see the possible types, rig
ht click on the ai read >> select type. Waveforms contain a time stamp of the data aquired and is often used.

For example of these programming techniques, see the shipping examples of LabVIEW.

Jeremy
0 Kudos
Message 4 of 6
(3,001 Views)
Jeremy:

I can't see the code (don't have LV at home) but:

I agree with your statement about having the loop just acquire data.
But instead of a shift register or global variables though, how about
a queue structure and having a separate while loop to write the data
from the queue to file?

Signal between the two loops that new data has been placed into the
queue with an occurrence. (Set Occurrence, Wait on Occurrence)

Write data to file in 64K data frames regardless of the size it was
put into the queue. If 64K is not available then don't write. When
>64K is available write 64K frames until 64K<.

If you do this you will minimize your CPU overhead and everything will
run as fast as it possibly can because unrelated functionalities will
not be forced to wait on each other to complete and the data integrity
in the queue will be preserved because the queue is a named kernel
object managed by the O/S, you won't have to worry about how much
memory will be needed by your program ahead of time, and the queue
will be "atomic" in nature so that data won't get lost unless the O/S
totally runs out of resources.

Doug De Clue
LabVIEW developer
ddeclue@bellsouth.net


Jeremy Braden wrote in message news:<5065000000050000005F8F0000-1027480788000@exchange.ni.com>...
> For improved performance, you need to have the loop just aquire data.
> This means you will need to move the write to file which is slow
> outside of the while loop and just write all the data at once.
>
> This transistions into the problem of how to build the array and this
> really depends on how you want to acquire data. If your sample size
> is small enough (you will have to do the math), you can have the ai
> read just read all the data and return one final array. This is the
> simplest method of all. If you want to do continious acquisition, you
> will need to build an array. There are two good methods. The best
> method is to create an array ahead of time with initilialize array,
> feed this into a shift register and write the data as it comes in to
> the appropriate positions in the array. The other method is to use
> shift registers and the build array function to add the new data to
> the previous values. Be sure to right click on the build array and
> select concantenate.
>
> The next concern is the time stamping. Bear in mind that your data is
> collected in regular intrevals so you can know the scan rate and the
> initial time so you know when all the samples were taken. Now you
> need to be concerned as to when the data acquisition is actually
> started. It is usually not important to know when exactly (greater
> precision that a ms) an acquistion started because the pc is a self
> contained acquistion system. If this information is important you
> need to consider using a trigger to start your scans.
>
> Finally, you have a number of options to get the aboved mentioned
> data. AI start and AI read both have terminals that convey info. You
> also have the option to have the data presented in a number of ways.
> To see the possible types, right click on the ai read >> select type.
> Waveforms contain a time stamp of the data aquired and is often used.
>
> For example of these programming techniques, see the shipping examples
> of LabVIEW.
>
> Jeremy
0 Kudos
Message 5 of 6
(3,001 Views)
You are right. Queues do make sense in this program. I forgot to step back and look at the even bigger picture. Thanks for your input.

Jeremy
0 Kudos
Message 6 of 6
(3,001 Views)