LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling at a different frequency simultaneously in one program

Hi Forum,

 

I have recently developed a Labview program to continuously record current measurement from 20 different anodes at a sampling frequency of 50Hz.

 

Now I need to include temperature measurement as well from each of the 20 anodes simultaneiously but at a different sampling frequency (5 Hz for example). What is the best way to do it? Would it be good to include another timed loop for the temperature measurement?

 

I have attached the project I have developed and it will be greatly appreciated if someone can have a look and give me some opinions. Thanks!!

0 Kudos
Message 1 of 13
(4,157 Views)

Hey Bautistuta002,

If you want to sample at a different frequency I think your option here will be to use a second timed loop running at the slower frequency. I might be able to better suggest a solution if I understood your application better.  What is the purpose behind sampling the same analog inputs at different frequencies? If you wanted to just update the front panel at a slower rate you could just write out every tenth value that you sampled instead of sampling in a completly separate loop.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 2 of 13
(4,122 Views)

Thanks for the reply Kevin!

 

The application of this program is to measure anode current signals from 20 individual anodes in a reduction cell. Now I would like to measure temperature from those anodes as well but at a lower sampling rate as we figured we will not need as much temperature data for our analysis purpose. So the analog inputs are actually different.

 

What I have in mind is to introduce another 20 shared variables (just like the current signals variables) and put them in a seperate timed loop just like what I have done with current signals measurement. I am however a bit reluctant to use the exact same method because of this other problem I am experiencing with my program (which I have asked in a seperate post). The problem is that my program cannot achieve the desired sampling frequency of 100Hz and I am suspecting it is related to the write to measurement express Vi I am using.

 

 

0 Kudos
Message 3 of 13
(4,119 Views)

Why not put the thing to be sampled at a lower frequency in a if statement within the main loop so that you can read this every nth iteration. So for instance, if the main loop is running at 50Hz and you read the temp every 10th iteration then it would be sampled at 5Hz. You can do this by dividing by 10 and testing if the remainder is zero.

 

Is this a real time system?

0 Kudos
Message 4 of 13
(4,108 Views)

Hi myle00! Yes this is a real time system.

 

I probably didnt clarify my issue, the program I have attached only measures anode voltage/current signals and now on top of that I would like to measure temperature as well. So I will need to introduce 20 more variables and repeat pretty much everything I did except for 20 different shared variables.

 

I am however a little reluctant to use this same method as it will require extra network variables and another "write to measurement" express VI. I was told that this express VI tends to slow things down and might be the cause of my other problem associated with the program (failure to reach desired sampling frequency of 100Hz; which I have posted in another thread).

0 Kudos
Message 5 of 13
(4,106 Views)

Hey Batistuta002,

You definitely would not want to do anything that accesses the memory manager inside your time critical loop.  This would include allocating arrays, File I/O, and several other things.  More of a discussion of what you want to avoid in deterministic code can be found here:http://zone.ni.com/devzone/cda/tut/p/id/3898  To write data from the deterministic time critical loop you will want to use something like a Real Time FIFO.  The use of these are descibed here:http://zone.ni.com/devzone/cda/tut/p/id/3934.  For updating different shared variables at a different rate I think your best option is to use a second timed loop at a lower priority and rate than your 100HZ loop.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 6 of 13
(4,093 Views)

Hi Kevin,

 

I don't fully understand the concepts of FIFO. I am writing the data into the variable "variable 1". I enabled the options of RT FIFO. Is that not good enough? By using FIFO does it mean I have to use one of the FIFO create, FIFO write functions?

 

I also didnt fully understood the concept behind buffer variable even though I have included that in my program. It was an advice given by my supervisor that I blindly followed. Can you please breifly explain the significane and the purpose of writing "variable1" into "buffered"?

 

Thanks in advance!

 

Vincent

0 Kudos
Message 7 of 13
(4,073 Views)

Hey Vincent,

If you are using a shared variable with the RT FIFO enables that is good enough to maintain determinism in your application.  The purpose of the RT FIFO is make it so that your code is not waiting on memory access when reading the value of a shared variable.  A more in depth description of this topic and buffering is located in this arcticle:http://zone.ni.com/devzone/cda/tut/p/id/4679.  Please post back with any additional questions.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 8 of 13
(4,057 Views)

Thanks Kevin!

 

I have just implented the changes for the additional temperature measurements. As you suggested previously I put in a seperate timed loop to acquire the temperature signals (I only included 5 for testing purposes). Then I performed the same steps of what I did with the voltage measurement previously. However I am experiencing a few problems.

 

1) The resulting data log for temperature measurement only contains one sample of data.

2) The format is incorrect. It's meant to contain n rows by 6 columns (5 temperature + elasped time). However it is now in one column. The settings I used in write2meas.vi is exactly the same and I just cannot figure out why two write2measurement VI with same settings can produce two different formats of data...

I have attached the lvm files (one with the desired format and one with the incorrect format) to illustrate my problems clearer.

 

I have also attached the newer version of my programs. Can you please have a look again and give me some advice? Thanks a lot!!!

0 Kudos
Message 9 of 13
(4,040 Views)

Hey Vincent,

 

I took a look at your code and I have a couple of suggestions.  You should not need two separate loops to write between the variable named variable1 and buffered1.  Since you have the RT FIFO enabled on buffered 1 you can write directly to that variable in the timed loop.  The same goes for variable 2 and buffered 2.  I also noticed that in your buffered two variable you have different numbers of elements in the buffer and the RT FIFO.  You will want the size of the array to match in these locations.  If that doesn't fix the issue you are having with only one column of data in the measurement file I would start by working back from the write to measurement file to see where the data is being truncated (either by using probes or front panel indicators).  If you can figure out which section of code is causing the error then we should be able to figure out why that is happening. 

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 10 of 13
(4,024 Views)