Streaming Data From Labjack U6


mikeho

Recommended Posts

Hi there, I have just started using DAQexpress with a U6 unit and mostly all is working fine but I do have some fairly basic questions.

1. Is it possible to stream data from the U6 AND retrieve using timed command polling at the same time - I just get a 'stream scans overlapped' error if I try this.

2. Is it possible to get the internal temperature (channel 14) streamed - I can read it as a timed value correctly but get a value about 200 too high when I stream channel 14.

3. I assume that scaling of streamed data is not possible as it is with polled data - is that correct?

4. How do I read (stream) differential analogue inputs from the U6? I have used the following

AddRequest(0, LJ_ioADD_STREAM_CHANNEL_DIFF, 2, 0, 0, 0) // Ain1 pressure

but still seem to get single ended data from Ain2

That's all for starters - hope you can shed some light on some/all of the above.

Many thanks,

Mike

Link to comment
Share on other sites

1. Is it possible to stream data from the U6 AND retrieve using timed command polling at the same time - I just get a 'stream scans overlapped' error if I try this.

Yes. I added a comment to the end of Section 3.0 of the user's guide:

http://labjack.com/support/u6/users-guide/3

I was able to get that same error if streaming real fast (50 ksamples/s) and then doing an AIN read by c/r. That is not the correct behavior, so we will look into it. The c/r AIN read should return an error an not affect the stream.

2. Is it possible to get the internal temperature (channel 14) streamed - I can read it as a timed value correctly but get a value about 200 too high when I stream channel 14.

No. I updated Section 2.6.4 of the user's guide:

http://labjack.com/support/u6/users-guide/2.6.4

4. How do I read (stream) differential analogue inputs from the U6? I have used the following

AddRequest(0, LJ_ioADD_STREAM_CHANNEL_DIFF, 2, 0, 0, 0) // Ain1 pressure

but still seem to get single ended data from Ain2

On the U6, the positive differential channel must be even and the negative differential channel must be +1. So, you need to do AIN2-AIN3 and thus you need to put in 3 for the x1 parameter. Again I added some info to the user's guide:

http://labjack.com/support/u6/users-guide/2.6

http://labjack.com/support/u6/users-guide/2.6.1

http://labjack.com/support/u6/users-guide/4.3.3

Link to comment
Share on other sites

I have to say that I am very impressed with your fast response to my questions - many thanks indeed. The differential analogue streaming now works a treat.

Ditto the scaling of the streamed data - don't know why I thought that did not work ;-)

To get over the 'stream scans overlapped' problem I now just stop the streaming every few seconds using a sequence, take the reading of the internal temperature sensor and start the streaming again.

Thanks again, Mike

Link to comment
Share on other sites

  • 3 years later...

Hello,

 

I'm very new to using DAQFactory with LabJack and data acquisition in general.  I am trying to measure light and temperature at the same time using analogue inputs. The light I will be measuring is a high power LED and clearly oscillates in intensity around 120 Hz (http://i.imgur.com/miqnYkt.png).  This oscillation means the sampling frequency can change the reported intensity (esp if the sampling primarily falls on a high or low end of the period).  I thought the best way obtain a true average was to stream the light data at around 5000 and average across the period.    I've played with DAQFActory examples for streaming one and four channels as given here: http://labjack.com/support/ud/examples/daqfactory and I've had some luck but still get minor oscillations within my average.  

 

 

So I have a few questions: 

 

1) Do I have to stream the temperature data if I need to stream the light measurements?  We don't need to sample the temperature reading 5000 times a second and I know the streaming takes a lot of power.  We will also have a pH sensor and flow meter connected to the analogue inputs of the LabJack at a later time.  

 

2) Do you have any advice on capturing the true average of the light without using stream mode? 

Link to comment
Share on other sites

  • 2 weeks later...

1) that depends on which LabJack you have.  Also, you should ask LabJack about what sort of oversampling it does.  Depending on the model, I believe if you set the resolution higher, the LabJack itself will oversample to achieve that resolution anyway and thus automatically average.  But again, ask LabJack.

2) I'm no electrical engineer, but a capacitor across the input would smooth out the oscillation for you.  You'd want to calibrate after it was smooth, but it should work.

Link to comment
Share on other sites

When trying to smooth a signal with a known noise frequency, make the sample interval a multiple of the nose period. That will prevent minor oscillation die to phase alignment.

I also don't think you need to sample at 5khz either. 1khz would give you 8 samples per lobe.

The other thing you might try is a sample rate slightly out - of - phase with the 120Hz, then calculate the length of the phase alignment cycle (how long does it take before a sample hits at the original point on the natural oscillation) and make your averaging time a multiple of that (probably at least 3x).

Link to comment
Share on other sites

Actually, the higher the sampling rate, the more smoothing.  If you only sample at 1khz with 8 oscillations per second and average down to 1 second data, you can expect to reduce the oscillation height to up to 1/8th the original depending on how phase aligned you are. 

Link to comment
Share on other sites

In general yes, but if your signal allows care to be taken with phase alignment, then you should be able to get as good a filtered signal with a substantially lower rate than otherwise. If you don't get the phase alignment, high sample rate can't completely correct for that.

Link to comment
Share on other sites

1) "Do I have to stream the temperature data if I need to stream the light measurements?" Yes. While streaming, the analog inputs can not be sampled in the standard command-response mode.

 

2) "Do you have any advice on capturing the true average of the light without using stream mode?" There are a lot of options here.

  • Using higher resolution settings will reject some of the noise.
  • If you are reading the other inputs at say once per second it would be easy to read light 10 times a second and average the values that you get. You could also use a running average of the last 10 or 100 readings.
  • The before mentioned passive filter could also work. Though it would probably need to be an RC filter tuned to allow the desired rate of change through and depending on the LJ and desired resolution a buffer may be necessary to prevent problems caused by the LJ's switching capacitance. Just be sure to use a capacitor that is large enough that the U6's ~300pF of input capacitcance doesn't cause errors. 1 µF or larger would be good.
  • Stream at a high data rate and integrate over one or more periods. You could switch stream on for a little more than 100ms and average over an even number of periods. For example if you stream at 12000 Hz for 110 ms (Slightly longer than necessary to make sure you don't come up short a sample or two.). Then average 1200 samples (100 per period so 1200 = 12 periods all averaged together.) That should produce good results and doesn't require you to stream your other sensor as well. Also has the advantage of not needing extra hardware.
Link to comment
Share on other sites

If you are seeing a real 120hz oscillation and not just noise, you need to think about what number you actually want to get.  If you just want the biggest peaks, you can always sample at, say, 1khz, then look for the max in each one second block.  Or for that matter each 0.1 second block then average 10 maxes to get a single averaged 1 second reading.

Link to comment
Share on other sites

Thank you all for your great feedback. I really appreciate it!

 

I was wondering if anyone knew how to average a set of scans rather than a rolling average like I believe the MEAN function does on DAQFactory. For example, assume that I scan the light intensity at 4800 scans/second and every time I get a new set of 4800 scan,  I want to average them all to get a single value which is the average of the last second. 

Link to comment
Share on other sites

Actually, mean gives you the mean of whatever array of data you give it.  If you do mean(mychannel) then it will do the mean of the entire history (not persist since I didn't subset).  To take a big history and make it into a smaller # of data points where each is the average of a 4800 boxcar, you'd use on of the boxcar functions.  Smooth() does a running average.  But in your case, probably the easiest thing to do is create a second channel to hold the average, a Test channel with Timing 0.  Then create a sequence that goes out every second and takes the average of your input channel for the last second and puts that into the second channel.  Something like:

 

while(1)

   avgChannel.addValue(mean(inputChannel[systime(),systime()-1]))

   delay(1)

endwhile

Link to comment
Share on other sites

Helllo,

 

Thanks for the tip! It was very helpful, however, instead of writing the data files to a channel , I wrote them to a text file directly! I don't need to scan at a high frequency all the time, just once every 5-10 minutes to get an averaged light reading. In fact, I also will be recording temperature and pH as well from the analog channels.  I wrote a sequence for each variable labeled, 'recordtemp', 'recordpH, 'recordLight.'  I then made a master sequence that sequentially calls each one of these over a 5 minutes interval.  However, I'm not using stream mode for the other sampling so every time stream mode is turned on for light sampling, errors are spit out continuously because the other channels can't be accessed (even though I'm not calling for them to record anything).  The overall function still works for recording data, I just don't know how stable this method is. In fact, I noticed after 16-24 hours the MasterSequence turns off and I think it's related to this instability. Would you recommend using stream mode for all sampling functions even though high frequency scanning isn't needed for two of them? Do you have any other suggestions? 

 

Thank you so much!

Link to comment
Share on other sites

You could always turn off acquisition on the other channels when streaming runs, then start it back up afterwards.

 

MasterSequence turning off is likely due to some other error.  You can prevent that by adding some error handling (try / catch blocks)

Link to comment
Share on other sites

After reading through both the DAQFactory manual and LabJack/DAQ manual I can't figure out how to turn acquisition on and off via a sequence.

 

I set the timing to 0 in the main channel area. Then I tried starting my sequence by setting the channel.timing = 0.1 and at end of sequence changing it back to channel.timing = 0 to turn off acquisition but that gives me the same values over and over again. 

 

Any direction to forums/manual sections where I can read more on how to do this?

Link to comment
Share on other sites

There are two ways:

 

1) set the timing to 0 then back to 1:

 

myChannel.timing = 0

myOtherChannel.timing = 0

channel.restart()

 

The channel.restart() is required at the end, otherwise the system just keeps ticking along at the old timing interval.

 

2) put all your inputs in a group, set the timing to 0, then in a sequence use: channel.readGroup() to trigger the reads.  Stop the sequence and the acquisition stops:

 

while(1)

   channel.readGroup("myGroup")

   delay(1)

endwhile

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.