08-27-2009 02:53 PM
Hi,
I have four loops which acquire data at different rates.
First loop acquires data at around 1000 times a second, second loop acquires data at around 200 times a second and third and fourth loop at a similar rate.
All the data mentioned above is read from a single device. So I have written a subvi which reads data from a channel that is specified as an input to this subvi. The subvi actually writes this channel number into the ports of the device which inturn places this data in a two ports [for any read request](MSB and LSB) and this data is read and returned out of the subvi.
The setup works really fine and if u query a channel number, the data in that channel is obtained from the subvi.
But since all these loops use the same subvi,which makes the device write the data in its ports, I doubt that there could be synchronization problem.
For example, if I am reading the data from channel 1, the result will be placed in ports 6 and 7 in the device that will be read by the subvi and given out. At the same time, if I read channel 2, its data will be placed in ports 6 and 7. So the interleaved execution of the loops might result in one loop reading the data that the other loop needs to read. So this subvi should be a synchronized block where only one thread can go in at a time.
I have attached a screen shot of the block diagram that is designed by me now. Please help me solve this synchronization problem.
Appreciate your help.
Thanks,
VJ
08-27-2009 02:57 PM
I have attached a refined version as I forgot to handle the sampling rates for those loops.
Thanks,
VJ
08-27-2009 03:01 PM - edited 08-27-2009 03:03 PM
You provided a lot of details, but not any information to go on.
What is going on in that subVI? Are they reentrant? What is the device you are communicating with? What do you mean by channels vs. ports? You say the loops are running at certain rates, yet I don't see anytime functions in those loops.
If you want only one subVI to execute at a time, why not put them in series with each other? If you need to block parts of code from running at the same time, you should be looking at semaphores in the synchronization palette.
EDIT: You added a reply where you put in some timing functions. One issue you will probably have with those wait statements is that they are rather small. If you are communicating with a device inside that subVI, it is very likely that communication will take longer than the millisecond wait statement you put in the loop
08-27-2009 03:19 PM
I am having a coulbourn instrument lablinc which is used for psychophysiological experiments. So it has a couple of EMG, a couple of skin conductance coupler, etc. All these are connected to different "channels" of the single A/D converter that communicates with the computer. So for example, if the left EMG reading instrument is connected to channel 1 of this A/D converter, and right EMG is connected to channel 2 of this A/D, then to read the left EMG, I have to read the value in channel 1.
Ports are the ports that A/D converter communicates with my computer. So for example, if u wanna read the data from channel 1, you write channel number "0" (x-1) into port 5. Which will put the value from channel 1 into ports 6 and 7. This is the normal mode of communication from the A/D converter to my computer. So if I read channel 2's data, its MSB and LSB will be written in 6 and 7 again. So if I read them in an interleaved manner, I wouldn't get the data I desired to read most of the times. [This part is what is done in the subvi using a stacked sequence structure].
Because, one execution of the subvi (lets call this EXEC 1)would have indicated to place channel 1's data into the ports, and waiting while EXEC 2 (second execution of this subvi from other loop) which needs channel 2's data would have requested for channel 2. So EXEC 1 would read the data that EXEC 2 is supposed to read and vice versa.
Can you please tell me how to put these executions of the subvi in series when they are called from different loops at different rates?
And about the wait statements, I thought about it, but my project actually requires the data to be sampled at 1000 Hz. So I thought let me put these in and try.
I searched for synchronization in labview, but never got a clear article that discusses its features. Everything is absurd and seems unrelated.
I appreciate your comments.
Thanks,
VJ
08-27-2009 03:26 PM
I don't see how you are going to get real synchronization. You are communicating with a single instrument. While it may have different ports/channels for acquiring data, you are limited to sending your commands to it one at a time and reading the message back one at a time. You'll need to read the manual for that instrument to see if there is a way to set it for multiple, simultaneous acquisitions at a 1 kHz rate and just read the data back as a block. Is this instrument connected serially or by GPIB? Either way, I don't see any way you can get a 1kHz sampling rate on even only one channel if you are just trying to communicate with it to read 1 sample at a time.
Considering you want to communicate with a single device, it doesn't make sense to spread the communication out to 4 different while loops. Communication with a single device should all be done in a single loop. Now once the data is acquired, and if you need to do data processing on the data in parallel without holding up any communication loop, that is the time to pass the data off to other parallel loops using a producer/consumer architecture by way of queues.
08-27-2009 03:26 PM
Please clarify: You write a channel number to the external device and it responds with data. The channel number always goes to the same place in the device (regardless of its value) and the data is always returned via the same two bytes (MSB and LSB), regardless of the channel selected. Is this correct?
If it works as I described above, I would have all the communication with the external device done by one subVI. It would be given the channel numbers and the sampling rates for each channel. It would send a request (channel number) to the external device and read the two-byte response. The response would be placed into a queue for that channel. The graphing loops would dequeue the data and display it and do any other processing of the data. Those loops would run much more slowly since the human operator could not interpret more than about 5-10 updates of the graphs per second.
What you are describing is a software-timed data acquisition system. You will not get reliable timing at the millisecond level with a desktop OS. Also, because the smallest increment of timing for Wait (ms) is 1 millisecond, you cannot read one channel 1000 times per second and three channels 200 times per second each. At BEST you can get 1000 readings per second aggregate for the four channels. For example you could read the channels in the following sequence: 1, 2, 1, 3, 1, 4, ... With a 1 ms delay between readings you would read channel 1 every 2 ms (500 samples per second) and channels 2, 3, and 4, each, every 6 ms (167 samples per second). Many other combinations are possible but none will give you the timing you wanted.
If you read the device as fast as passible (with a 0 ms Wait), you would be constrained by the speed of the external device. But you would not have good timing information about your samples.
Lynn