From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read 2 channels at different frequency

Hello:

I need to read 2 channels (PCI 6221) at different frequency, CH0 at 50 Hz and CH1 at 5000 Hz (Labview 2010, Windows XP) . The card works at 5000 Hz continously. I have to control a process at 50 Hz with CH0, and we have to save CH1 data when an event happens and for an specific time, (for example 15 ms).

We have two paralell loops, one for the readings and process control and the other for the events.

When the event happens we activate a boolean variable that enables data into array. At first sight it works Ok, but I have variable delays in time.

At 15ms and 5000 Hz, for example, we should save 75 data, but sometimes we have 70, 80 or 90 data.

The problem gets better as the main loop works faster (2ms), but it is not possible for us because we need longer time to use PIDs functions and graphs data. We think the problem is due to delays between loops.

Do you know another way to minimize the delays and program it better?

 

Thanks.

0 Kudos
Message 1 of 4
(2,284 Views)

There are several issues with this architecture, most notably you should not have 2 event structures, you are saving data in series with data collection which will slow down the data collection, you are using locals to pass your arrays instead of wires (this makes copies and slows down your loop) and you are using value set property nodes when you dont have to.

 

You should investigate a producer consumer architecture aor at least move your daq and process/save to seperate loops.

 

I would put daq in its own loop collect 2 channels at 5000hz, process the data and send save it in a second loop if you are trying to process the data fast, this way you can save the data in large chunks instead of saving it at a high rate.

 

I am not trying to be critical of this code, just pointing you in the correct direction for LabVIEW development.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 4
(2,280 Views)

Dear Paul:

Thank you for your quick answer.

I do not understand very well what you are proposing. I know it would be better to use a loop only for data adquisition and for PID control, but if I use wires to pass variables between two loops I would not be able to use the data until the first one finishes, isn`t it?

This vi is a small part of my project.

Actually I have to control a temperature process with CH0 continously and at certain moments (for example, when we press a key) I have to read another analog input (CH1) and a encoder at high frequency during a fixed time (it should be exact), and save these data. CH1 and the encoder signal have to be perfectly sinchronized.

I have already this projetc done and it works ok but using two daq boards. Nowadays, I would like to improve the program using only the PCI6221 board, because I think it should be possible.

Some time before I tried to use queues and master/slave structures, but I did not improve the program. I think I should study better producer/consumer loops.

Thanks.

 

 

0 Kudos
Message 3 of 4
(2,277 Views)

As you suspect you can not pass wires between arrays because the serializes the loops and are nolonger parallel.  There are many mechanisms for passing data between loops however in labvies, the example finder shows many of them.  A brief introduction to them are listed below

 

Locals - not good since only holds one copy, requires memory copies, no protection from race conditions, limited to vi scope

Globals, same issues as locals except application scope

Queues- provides fifo (lossless history) easy to use, slight learning curve see producer consumer examples

Action engine/functional globals-  more design work but very flexable mechanism for passing data between loops, allows for data processing and passing between loops with a build in locking mechanism provided by the vi call- used extensivly by LV power users.

 

Also for passing data between itterations of loops it is prefered to use a shift register and wires rather than a local (more memory efficiens, better style and readability)

You might explore state machine architecture and using error wires instead of sequences to enforce order of operation in LV.

 

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 4 of 4
(2,273 Views)