LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timing when using state machine

Hi,

I need an advice regarding the following timing problem.

I have a state machine.

In one of the states I have to sample a DigIn for 2.4 seconds.

The samples have to be grouped in 12 groups of 0.2sec each.

Then I have to check how many times a DigHigh occurred in each of the 12 groups.

I am not sure how to accomplish that.

Can somebody please give me an advice?

Thank you in advance for all your suggestions.

(I am using LabVIEW 2009)

0 Kudos
Message 1 of 12
(3,764 Views)

Were it me, I would rely on my hardware to do the timing, and 0.2s worth of data 12 times.  The output will be a nice pretty 2d array, already bunched for processing.

0 Kudos
Message 2 of 12
(3,742 Views)

Thank you. I agree that once I get the array all will be a piece of cake.

Still, however, I am looking for a way for the software to accomplish the timing.

Any suggestions would be appreciated.

Thank you in advance. 

0 Kudos
Message 3 of 12
(3,684 Views)
What is your hardware? Pretty hard to provide a solution when that essential information is missing. What have you written so far and why don't you attach that? You aren't going to get very good resolution with just software timing of a digital input task.
0 Kudos
Message 4 of 12
(3,680 Views)

I am using NI USB 6509.

0 Kudos
Message 5 of 12
(3,673 Views)
So, an inexpensive device with only software timing. You have not posted any code but can we assume you just have a digital read inside a for loop with a msec wait? Do you want multiple samples during the .2 seconds? As I said, you aren't going to get very good resolution and there will be considerable jitter.
0 Kudos
Message 6 of 12
(3,658 Views)

You are right.

I am reading a DigIn inside a For Loop and would like to get as many samples during each of the 0.2 sec periods as possible.

Can you please give me an advice how I could achieve the best accuracy possible (for the hardware) and get the 2D array containing all 12 x 0.2 sec periods? I am sorry I can not post a sample vi but I will have no access to LabView before tomorrow.

Thank you in advance.

0 Kudos
Message 7 of 12
(3,650 Views)
One way is to use elapsed time function and exit an inner for loop when the .2 second target is reached. The result of the DAQmx Read of 1samp after it exits the for loop is a 1D array. Put that inside a for loop that runs 12 times and there's your 2D array.
Message 8 of 12
(3,633 Views)

Which of your timing requirements is more important to you?  Is the 0.2s window more important or is that a way to split 2.4s?

 

If you're more interested in the 2.4s, I'd consider processing the data as a collective after the full duration rather than splitting it up into 12 iterations.  You will be running on software timing.  That means you're going to deal with the OS inserting time as it sees fit.  You'll get closer to a solid block of 2.4s by going with one logging period than you will by using 12 logging periods.  If that isn't a concern, running 12 times will certainly make processing the data afterwards easier.

0 Kudos
Message 9 of 12
(3,626 Views)

Hi,

I created a simple vi (the DigIn is replaced by a Random Num generation and instead of 12 x 0.2 periods it is running 5 x 0.2 sec periods).

Is there a better way to time the inside while loop?

Also I have no explanation why instead of 1 sec. the total time reads 0.8 sec. (5 x 0.2 sec = 1 sec.)

0 Kudos
Message 10 of 12
(3,592 Views)