LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling frequency in while loop issue

Solved!
Go to solution

Hello,

 

I'm a student who is doing thesis about electrical vehicle monitoring system in labview. I'm collecting analog measurement data from usb-6009, transfer it over daq assistant and use state machine inside while loop to do monitoring process.

So, I have one state which determines sampling frequency of the loop cycle, and I've made able to change this rate in values of 0.1, 1 and 5 Hz. I've realised it with Elapsed Time Express VI which is in loop but outside case structure for states. I'm setting frequeny rate in Elapsed Time "Time Target" input, And the boolean "Time has elapsed" output goes to the case structure, which changes to the next state when the time runs out. In the next state it resets the Elapsed Time and the cycle starts from the beginning.

So, everything works fine until I see in my log file (txt file where I save the measurement values) that it made on the frequency of 5 Hz only 3 or maximum 4 samples per second.

I have pretty good computer with i7 processor and 8 gb of ram.

What could be the problem?

In the picture below it can be seen how I realised this with timer.

 

Thank you in advance.

Matej

sampling

0 Kudos
Message 1 of 6
(2,994 Views)

Looking at visible portion of your design, I can't tell if you are using that elapsed time vi to first wait specified milliSeconds and THEN doing your other logic which reads analog channel(s). Perhaps you could post the vi!

 

For example, in case of 5Hz, it could be that you are first waiting for 200mSeconds and then doing your analog read/etc logic which is taking another 100+ milliseconds.  If that were the case then you're essentially reading at 3.3Hz (which would explain why you're reading 3 or 4 readings).

 

In above case the fix would be quite simple - just use a "Wait until next ms multiple" AFTER you do a reading - in fact you can do it all in a very simple while loop without any case structure (unless if you're doing more things and/or need to grow your design in future, then state-machine would be best approach.)

 

Hope that I'm making sense...

 

-DP

 

--------------------------------------------------------

New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI


0 Kudos
Message 2 of 6
(2,982 Views)

Hello,

 

I'm sending my VI in attachment so you could have an overview to whole process. Explanation and titles are in croatian, but you will get the logic.

 

Thank you in advance

0 Kudos
Message 3 of 6
(2,965 Views)

Attach the subVI called "Sampling.vi".  The secret may lie in there.

 

(PS:  You don't need all of those index array functions.  Use one and drag the bottom border downwards.  You'll automatically get indices 0 through 7 in order without needing the other 6 Index Arrays or any of the constants to define the index.)

0 Kudos
Message 4 of 6
(2,960 Views)

O, I noticed now for the Index array. Thank you. Here you have the Sampling.vi

0 Kudos
Message 5 of 6
(2,956 Views)
Solution
Accepted by topic author ljobe_CRO

As I mentioned in my previous note, your problem is that you're starting a new target time for Elapsed Time vi AFTER your analog reading is completed.  This essentially ADDS whatever time is taken by Analog reading on top of the time you're asking Elapsed Time vi to wait.

 

I have modified your vi and I believe that should take care of your timing issue.

 

However, I would suggest using "Wait Until Next ms Multiple" because unlike the express vi you're using, the one I mentioned lets other processes do their job while waiting.

 

Hope that helps...

 

-DP

--------------------------------------------------------

New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI


0 Kudos
Message 6 of 6
(2,936 Views)