07-11-2014 03:12 AM
Helllo everybody,
I have a problem about the usage of CPU now i am using a realtime target (PXI-8186) with Daq (PXI-6259) to get 15 analog signals at the rate of 10kHz
at first i try to get signal at different rate but i found out that all of the channels share the same clock so i get the highest frequency that i desired after that i do
some data manipulation with displaying charts and use shift register to stack data in array of string finally i write the data to spreadsheet every 5 second, by doing this the CPU usage
is always 100% and reduce by the time the file is recordedto 71% or so and then start to increase to 100% again. I think the things that make CPU usage too high are
1. Time loop: because i set the period to be 10ms maybe this is too low.
2. The shift registered: may be it use too much overhead memory but i do not know other method to stack data before writing to a file
3. RAM too low: The RAM of PXI is only 256mb
4. Poor program arrangement: Because i am new to labview the program is not arranging correctly or i may use some inappropriate structure.
My program is very messy sorry about it because i avoid using SubVI and i am new to labview. Please help any suggestion is apperciated. Thanks in advance.
Best regard
Wuttikrai
07-11-2014 03:31 AM
You defenetly have to put some effort to restructure your code.
Thing to avoid
Build Array: This will lead to memory leak when you use it un conditionally. You are building the array and keeping them in the shift register, which consumes your RAM a lot
Data Acquisition: Unless you don't have any specifi requirement don't acquire the data as a waveform as it packs additional data along with the real data you need. You can simply acquire the data as a DBL value and write that to a file.
Formula Node: You have all the mathematical functions available with LabVIEW so there is no need to use this.
Graph Display: Don't do this in RT itself, bring the data to the host and display it.
File Writing: Best method as always suggested is, put a queue and transfer the data to another loop but in your case you can send the data to the host and save it there. Also when you are using continous Read/Write operation in file use the Write to text file primitive along with Array to Spreadsheet function. Write to spreadsheet VI opens and closes the file everytime you execute.
07-11-2014 06:42 AM
Dear P@Anand
Thank you very much, this is the 3rd time you have helped me so far. But i still have one more question.
I understand every point except building array, if i don't use it i don't know how to collect the data (stacking) before writing to file every 5second.
Please give me some clue sensei. Thank you
Best regard
Wuttikrai
07-11-2014 07:15 AM
It looks like you are writing your data to disk every so often. For that reason, I recommend making it based on the number of samples you have instead of the time. With that you can preallocate your arrays with constants going into the shift registers. You then use Replace Array Subset to update your arrays. When you write to the file, make sure you go back to overwriting the beginning of your array. This will greatly reduce the amount of time you spend reallocating memory and will reduce your memory usage.
07-11-2014 08:47 AM
@greed wrote:
Dear P@Anand
Thank you very much, this is the 3rd time you have helped me so far. But i still have one more question.
I understand every point except building array, if i don't use it i don't know how to collect the data (stacking) before writing to file every 5second.
Please give me some clue sensei. Thank you
Best regard
Wuttikrai
Crossrulz already has given a good advice.
If you still struggle to initialize your array and use replace array subset, run the loop at 1KHz with "1" as dt and acquire single sample/channel. Here you can define the array size as 15 and use replace array subset and pass the data to another loop and pack the data send it to host. I believe 1KHz data is good enough to analyze the data.