LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer consumer with analog and digital inputs and outputs

Solved!
Go to solution

Hi Robert,

 

I am using a cDAQ-9178 with five modules currently installed (Analog input card, analog output card, two thermocouple cards and a digital IO card). The digital IO card that I am using is the NI 9375. I have added the clear tasks at the end of the consumer loop and now my program runs without error but just hangs and doesn't do anything.

0 Kudos
Message 11 of 27
(2,941 Views)
Solution
Accepted by topic author DarkMarc86

DarkMarc86,

 

With the 9375, you will not be able to use hardware timing for both a read and write task. You will have to use software timing in order to have both tasks perform simultaneously. This means you will need to remove the DAQmx Timing.vis from your digital tasks. You might also have to remove the DAQmx Write.vi that is before the DAQmx Start Task.vi from the Digital Output task as well.

 

You will not need to remove the timing VIs from the Analog tasks, since each Analog task is using its own module. 

 

Try removing the timing VIs and using some LabVIEW debugging tools like Highlight Execution to see if you are missing any errors anywhere.

Robert R. | Applications Engineer | National Instruments
Message 12 of 27
(2,923 Views)

Thank you very much Robert! You were right in that the hardware timing for the digital inputs and outputs was creating an error. I am now using software timing for both and the programs runs well. To be consistent, should I set my analog inputs an doutputs to be software timed as well? The data sampling is ccuring at 500 Hz but the data output is at 1hz.

0 Kudos
Message 13 of 27
(2,903 Views)

Robert, now that my digital inputs have had the 'DAQmx timing.vi' function removed and I am only left with 'DAQmx start task.vi' and 'DAQmx read.vi' functions, how do I set the sample rate to 500Hz? Currently the sampling rate is at the same frequency as the producer 'while loop' is executing,

0 Kudos
Message 14 of 27
(2,892 Views)

DarkMarc86,

 

I am glad to hear this is working correctly for you!

 

Below you will find a simple example demonstrating how to set up software timing in LabVIEW. Basically a Wait(ms).vi is needed in the While Loop with a millisecond value as its input. This will govern the loop rate, which in turn governs the rate of the data acquisition in software.

 

Voltage - SW-Timed Input:

https://decibel.ni.com/content/docs/DOC-25107

 

In regards to changing the Analog tasks to being software timed as well, this depends on how long the Wait(ms) is causing the loop to wait. You could run into buffer issues if you are acquiring a large amount of data quickly, but reading data in slowly. But if the rate of the loop and rate of the hardware timed task are close to one another, then it should not be an issue. You can try both and see which set up works better for you.

Robert R. | Applications Engineer | National Instruments
Message 15 of 27
(2,878 Views)

Robert,

 

Thanks for your suggestion. For simplicity I have changed all the data acquisition to be software timed, as per your example. However I am having some issues. If I set the 'DAQmx read.vi' functions to sample a single sample at a time and the 'wait(ms).vi' to 2, the loop seems to increment at 10Hz exactly for some reason, and not at 500 Hz. If I change the 'DAQmx read.vi' function to acquire multiple samples at a time (so that the samples get put into a buffer) I get this error:

 

Error -200284 occurred at control_v2_ML_simple.vi

 

Possible reason(s):

Some or all of the samples requested have not yet been acquired.

To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger,  make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.

Property: RelativeTo Corresponding Value: Current Read Position Property: Offset Corresponding Value: 0

Task Name: Heater testing lab analog inputs

 

I don't understand why this is happening considering considering when I was using hardware timing, I was still able to acquire 500 samples per second in the producer loop with no issues.

0 Kudos
Message 16 of 27
(2,861 Views)

DarkMarc86,

 

There are several topics from your post I want to discuss.

 

First, I set up a very simple example in LabVIEW of setting a DAQmx Read.vi to read 1 sample per channel for multiple channels (8). I placed a 2ms Wait.vi in the While Loop and was able to achieve a fast loop rate, much faster than 10 Hz. I believe the digital to analog conversion and Insert into Array functions could be drastically slowing down your While Loop, especially when there are 500 samples per channel and you are sampling from multiple channels from two different tasks. Try making a new VI with just your Analog Input task and see how fast you are able to sample.

 

The error you are receiving is a timeout error. This KnowledgeBase Article explains more in detail about this error and why you are seeing it. 

 

There is a difference between loop rate and sample rate. Looking at your code right now, you have it set up to read in 500 samples per channel for every loop iteration. If you had your loop rate set up to be 1 second, you would read in 500 samples per channel every second, 500 S/s per channel. So to read in 500 samples per second with a loop rate of 500 Hz, you will just need to read in 1 sample for every loop iteration.

 

Hope this helps!

 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 17 of 27
(2,843 Views)

It seems that I was having problems due to settings in my MAX tasks. I can get my program to work in two ways:

 

1. When I set my Labview program to acquire one sample at a time within the producer loop, with the loop iterating at 500 Hz and I set my all of my MAX tasks to acquire '1 sample (on demand)' at a time.

 

2. The other way I have been able to get it to work is; set my labview program to acquire multiple samples at a time, with the loop iterating at one per second, and setting only the 'analog input' task aquisition mode to 'continious samples' and the other three tasks to '1 sample (on demand)'.

 

The indexing and conversion from digital to analog waveform does not seem to affect anything.

 

I am going to have my program work using the second method, of the two above, because I would rather the samples get stored in the FIFO buffer and not have to iterate my producer loop quickly to take the load off the CPU.

 

The only thing that is still a puzzle to me is; why does it work when my 'analog input' task is in 'continious samples' mode and the other three tasks are in '1 sample (on demand)' mode? Could it be because my analog input tasks has 31 channels, whereas the other three tasks only have 4 or 5 channels?

0 Kudos
Message 18 of 27
(2,830 Views)

DarkMarc86,

 

When you select 1 Sample(On Demand) in your MAX task, this makes the task software timed. With Continuous Samples set in your MAX task for the Analog Input task, this is still hardware timed. To make everything software timed, you will have to have all tasks set as 1 Sample(On Demand) and have the loop rate at 500 Hz. 

 

This is my recommendation. Since the Digital I/O tasks have to be software timed, having all the tasks be software timed would be the best way to get your application to work correctly. 

 

The way your code is right now, you are receiving 500 samples per second in your analog task, but only 1 sample per second in your digital task, since it is set as 1 Sample(On Demand). 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 19 of 27
(2,816 Views)

Robert,

 

It seems that you are right and my code was actually not working correctly, even though I thought it was. When I set the 'DAQmx read.vi' function for the analog inputs to 'continious samples' with 500 samples to read, and a 1Hz loop speed, based on my testing it appeared that the sample speed was not actually 500 Hz. Instead it seem to take 500 samples very quickly (faster than 500Hz) and then wait and then sample again, and so on.

 

I have implemented your suggestion and changed everything to software timing. All four tasks in MAX have been set to '1 sample (on demand)' and all four 'DAQmx read.vi' functions have been set to sample at 'multiple channels, single sample' with the producer loop set to 500 Hz (2ms wait). Unformately at the moment the loop only appears to be cycling at 1Hz and I cannot understand why. I have disabled absolutely everything (the whole consumer loop, the que, and all other functions in the producer loop) other than the acquisition functions and the producer loop still only increments at 1Hz. I can see from task manager that the CPU usage is only around 10% and the Labview only uses 150MB of memory so I cannot understand what is limiting the producer loop speed. Could it be that the NI hardware is not capable? I am acquiring 31 analog channels and 4 digital cahnnels. Though I have had 31 analog channels being acquired with hardware timing at 500Hz with no problem previously.

 

My hardware is an NI-cDAQ-9178 chassis with an NI-9213 and NI-9207 for the analg inputs and an NI-9375 for the digital inputs.

 

EDIT: just noticed that the sample speed of the NI-9213 cards are max 75Hz, so I would still expect the producer loop to be able to run at 50Hz at least, and not 1Hz.

0 Kudos
Message 20 of 27
(2,804 Views)