LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer consumer with analog and digital inputs and outputs

Solved!
Go to solution

DarkMarc86,

 

I guess I should have asked for the hardware specs of your entire project sooner!

 

It is true that you will not be able to sample that thermocouple module at 500 Hz. The reason you saw 500 samples per channel earlier is that LabVIEW will just repeat the samples it has obtained. You most likely had 500 samples of the same value the way it was programmed before. 

 

However, you should be able to sample faster than 1 Hz, but not much. I will try to obtain some hardware and reproduce this on my end. 

 

I would recommend making a new VI with just the Analog Input task and set it to software timing and see how fast you can obtain samples from your 31 channels.

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 21 of 27
(1,388 Views)

Hi Robert,

 

I did this yesterday and found that I could sample the thermocouples somewhere between 1 Hz and 2 Hz with 16 channels enabled (single card). I think I have manged to get my program working. I have divided my producer loop into two seperate producer loops, one iterating at 1 Hz (thermocouples, voltage inputs and current inputs) and one loop iterating at 500 Hz for my four digital input channels. I have left my program to run overnight and monitored the number of cycles performed by the producer and consumer loops, to make sure that they are in time with eachother, and the result is 54,550 cycles by the producer loop running at 1 Hz and 54,528 cycles by the consumer loop running at 1 Hz. I have a que in between these two loops, which as I understand, is supposed to keep these two loops synchronised. At the point at which I sample my que, there should be zero elements left in it at the end of the consumer cycles, but looking at it right now, there are now 22 leftover elements in the que (which is exactly 54,550 minus 54,528). I suppose this isn't a massive problem, but it means that in an overnight test, I will lose around 22 seconds of data which is not desirable.

0 Kudos
Message 22 of 27
(1,372 Views)

DarkMarc86, 

 

I am glad to hear you have this pretty much working.

 

In order to not lose those 22 samples, you will need to add functionality to stop the producer loop, then have the consumer loop wait until there are no more samples in the queue to stop. This way the the consumer loop will keep functioning even after the producer loop has stopped.

 

This functionality is demonstrated in one of the LabVIEW shipping examples named Simple Queue.vi. This can be found under Help >> Find Examples... in LabVIEW. 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 23 of 27
(1,360 Views)

Robert,

 

I don't seem to have the 'Simple Queue.vi' program in my examples, nor can I find it on the web.

 

I am worried that you suggest a solution that involves halting the producer loop. Since I am working on software timing, I want the producer loop to be consistently looping at 1 Hz and not stopping at all. I also need the consumer loop to be incrementing at 1 Hz in time with the consumer loop. Maybe I need to be looking at the timed loop structure?

0 Kudos
Message 24 of 27
(1,346 Views)

DarkMarc86,

 

First, I might not have explained myself clearly in the last post. The functionality I am talking about is when you are done running your program. Say you let your program run overnight, and in the morning, you want to stop it and look at your data. You would hit the Stop button to do so. What I am suggesting is adding functionality in your code that when you hit that Stop button, whenever you do it, it will tell the Producer loop to stop BUT have the consumer loop keep going until there are no more samples in the Queue. Then when the Queue is empty, say when those 22 samples are no longer there, then your program will completely stop. This is not going to have the Producer Loop stop and start during your program, it will just stop a little time before the entire program stops when you tell it to. 

 

If you can, maybe try searching through the directories on the Example Finder. I found it under Optimizing Applications >> Synchronizing Tasks >> Simple Queue.vi. If you are still not able to find it, let me know what version of LabVIEW you have and I can attach it on the forum.

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 25 of 27
(1,335 Views)

Robert,

 

I have checked my examples and it seems that my Labview 2012 (service pack 1) does not seem to have the 'simple que.vi' example.

 

I don't understand why we can't prevent the que from building up in the first place. Surely there has to be a way to synchronise the loops?

0 Kudos
Message 26 of 27
(1,319 Views)

DarkMarc86,

 

The reason we can not synchronize the loops is because the producer loop is generally faster than the consumer loop. The producer loop just reads in data very quickly, while the consumer loop takes more time to process the data. Also, the queue is designed to build up with the samples so you do not lose any data. 

 

I have saved the Simple Queue.vi to be compatible with LabVIEW 2012. I recommend implementing the functionality you see in this code and watch how it works. 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 27 of 27
(1,306 Views)