LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer consumer timing

 

Back again

 

Thought I was getting somewhere now I am at another brick wall.

 

Bit of background:

 

I have a producer consumer set up. In the producer loop there are 2 DAQmx read VI's reading from a Pressure task and a Temperature task. These are multiple channels, 1 sample, outputtng a 1D wave form. This loop is set to run every 20ms. The two tasks were created using DAQmx Create Channel VI's and DAQmx Start Task VI's. The producer loop feeds a display on the front panel with the sensor values and this hopefully is refreshed at the 50Hz I have asked for. Secondly the loop bundles up the waveforms and puts them in a queue where they are picked up for logging by the consumer loop. In the consumer loop I have a wait 1000ms timer and a Write to Measurment File Express VI to do the logging. This is supposed to log at 1 per second.

 

The queue is set to enqueue at opposite end, and the max queue length is set to 1. I.E. I only want to log the value at that specific second, but I want to show the data on the front panel at 50 times a second.

 

Now heres my problems:

 

1) I replaced the DAQmx Create channel's with a MAX project task wired into my DAQmx Start Task VI. As expected the thing picks up and displays the sensor values as it did before. However there is now a problem logging. Before when I had the DAQmx Create Channel, the logging recorded my values correctly at 1 second intervals. The time stamp in the X column went up by 1 second for each set of results. But now, with the MAX project task (needed because of custom scales and differing min/max values for different sensors), The logging still seems to happen at 1 per second, but the time stamp intervals are the same as the sampling rate set in the task!!! (ie at 50Hz the time stamp goes up 20ms for each result even though the results are being recorded at 1 per second)

 

2) The timing just seems out of whack.

 

I keep getting errors that the requested data no longer exists, that it was there but then was over written. Increasing the buffer size or sampling rate is supposed to remedy this... but what sampling rate? the rate set in the task? or the loop iteration speed? I dont understand.

 

Secondly, despite telling my consumer loop to wait one second between picking up stuff out of the queue to log, it seems to be going round nearly the same pace as the producer loop. To top this off the producer isnt going round at the speed I asked it too either! I put indicators on the loop counters to see this. they are going round at maybe 2Hz.

 

I have included my VI's

 

What am I doing wrong, its really bugging the crap out of me!

0 Kudos
Message 1 of 17
(3,725 Views)

Here is what I would do to start

Tim
GHSP
Message 2 of 17
(3,713 Views)

Thanks for that

 

Not sure what you have done though. What is the purpose of the time stamps? They dont appear to do anything....then again I am a complete novice.

 

Also, as you have set it the two loops appear to go round very fast and at the same time. If I change the time out constant on that event structure it all goes to pot again. Why is the bottom loop controlling the overall speed of the VI? Why cant it go round once per second and pluck whatever data is in the queue and log it?

0 Kudos
Message 3 of 17
(3,703 Views)

In your original VI, try changing Enqueue Element to Lossy Enqueue Element. Keep the size of the queue at 1 element. See if this takes care of your first issue.

 

In your MAX task, what are the Acquisition Mode, Samples to Read and Rate(Hz) settings? Are they the same for both tasks?

 

JohnCS

Message 4 of 17
(3,692 Views)

same for both tasks yes

 

I have continuous sampling, because I want it to keep going indefinitely until i say stop. The buffer size is 1 (samples per channel box) and the rate is, at the moment, 50Hz.

 

This is the same for both pressure and temperature channels.

 

Lossy Enqueue appears to be doing exactly what I want! Excellent!

 

However I keep getting this error

 

Error -200279 occurred at VDU3_1.vi

Which is to do with the requested sample being missing. It says it was there, but then it was over written. Is my  producer loop going too quickly now? Its looping 2 x as quick as the samples are being generated.

0 Kudos
Message 5 of 17
(3,688 Views)

any idea why if I set the second loop to go every second, it noting down time stamps seperated by only 10ths of a second? 1000ms is definitely 1 second in time.

0 Kudos
Message 6 of 17
(3,686 Views)

The reason you would use get time and date in seconds to to ensure that you log every second. If you use the 1 second wait then you do not take into account the exicution time of your loop. If you add more to the loop in the future than you will see that you do not log every second as you thought. If you loop took 500ms to exicute and you have the 1000ms wait then the actual excution time for recoding to file is 1.5 seconds not 1000ms as you desired. The way I did it will always give you one second unless you exicution time for your loop exceeds one second.''

 

I did make one change to the vi. I shoulod have put the write in the true false case so that the write only happens when the 1 second has expired.

Tim
GHSP
Message 7 of 17
(3,678 Views)

ahhh I see, that makes sense now, I can follow that

 

At first it just looked a bit strange! Will try it now!

0 Kudos
Message 8 of 17
(3,674 Views)

Ok This seems to work ok

 

Still using the lossy enqueue method, though I am unsure whether this makes a difference at the moment.

 

However, the time stamps in the file still read

 

0.1

0.2

0.3

0.4

...

1.0

1.1

 

etc, its going up in tenths.... now this isnt anything to do with that time check thing, this must what is in the data in the queue.

 

 

Also, around 1200 loops, the thing dies with that error..... should I just increase the buffer size?

0 Kudos
Message 9 of 17
(3,671 Views)

is it going to be better to scrap the use of wave forms, go for a single DBL value for my data and some how add the time into it later? or will the Write to measurement file express VI put in current time for me? If i can get start and finish time and a time stamp for each record then I can just do the relevent stuff in excel.

0 Kudos
Message 10 of 17
(3,665 Views)