12-02-2013 04:06 PM
Hi,
I've been creating an VI using producer consumer loop. In producer loop, every loop take 1000 samples at the rate of 40000/s(or 40000s/s devided by number of channels) and the consumer loop will average the data in a way corresponding to the "sampling rate" value on the front panel. The "sampling rate"represents the data rate on the chart and in the saved data file. If it's too slow,say 1 sample per second, then the producer loop will just wait for some time.
So far the VI run smoothly, but there's one big problem. Each time I adjust the amplitude of input signal and the change doesn't show up on the chart untill several seconds later. When the "sampling rate" is really slow, the delay could be 1 minute! It's the first time I have ever used producer consumer loop and I 'm really confused of what causes this time delay.
Could someone give me a hand with this?
Thanks!
Yaqiong
12-02-2013 04:48 PM
You should consider further separating your tasks. For instance, the writing to file should be in its own task since file I/O can really cause delays in your processing. Also, I would separate your data processing (averaging) from the UI updates. The UI updates can be within a task that is using an event structure. It can get the data updates to update the chart but it can also quickly respond to the changes in your amplitude. I would also be very careful of the wait in your producer loop. This could starve the CPU.
One last note. Your code could really benefit from a cleanup. Your coding style is quite a mess and it makes reading (and maintaining) your code much harder. For example, your code should generally read from left to right. Running wires backwards, having outputs on the left, lots of bends, etc all lead to messy code that is difficult to read.
12-02-2013 05:26 PM
My God!
It's urgent to read this book :
The labVIEW Style Book (Peter Blume)
12-02-2013 11:37 PM
Thank you for replying! And sorry about the mess. For "further separating tasks", do you mean creating one more customer loop? Should I move the chart to producer loop? And why is an event structure needed?
I know the wait could be a trouble sometimes but it is the only way I can think of, to be at really slow rate and avoid taking too many data.....
Once more, sorry about the stupid questions, I am really terrible at labview programming.