Streaming and Counters


craig

Recommended Posts

I've reviewed the streaming sample file "UE9_Stream_Simple.ctl" and have modified it for my purposes. I've built an IR emitter/receiver to use as an optical tachometer. I have a counter that records a "1" whenever the IR receiver (it's a photo-transistor) senses any reflected IR from the spinning object. It is working well, but there are a few things I don't understand.

1. What determines the number of rows of data points that I get in the logging file?

- Timings are all set to 0 except for Channel0 is set to 1.0. Resolution is set to 16, and the clock to 750 Hz.

- I am streaming Counter0, AIN0, FIOx (i.e. channel 193), and a virtual channel called RPM that's calculated from the Counter0 data, in Counter0's Event tab.

- This line is in the streaming sequence (as based on the sample)

Device.LabJack.AddRequest(Var.d_number,"LJ_ioPUT_CONFIG","LJ_chSTREAM_SCAN_FREQUENCY",1000,0,0).

- I understand that a "scan" is one read through of all the data (i.e. one row of data in the output file), and a "sample" is a single piece of data (i.e. one "cell" of data to use Excel terminology). So I would read this to mean scan all the channels 1000 times per second. So 1000 rows of data per second. Is that correct?

- with all off the above settings, I get one row of data for every 0.002 seconds (so 500 scan per sec). The data file has 5 columns (TheTime, AIN0, Counter0, FIO0, RPM). The first two columns are full of data, the last three only have data points every 1.0 seconds (as expected with Counter0's 1.0 sec timing).

3. When the logging file time alignment was set to 0.05 sec, the data file only contained one row for every 0.05 seconds, rather than one for every 0.001 sec as I was expecting. When I changed the alignment threshold to 0.001 seconds, I ended up getting a data file with one row for every 0.002 seconds. Is it correct that the alignment threshold needs to be no more than desired scan timing?

4. How many "channels" is that? Is channel 193 a single channel or is it 16?

5. When I used a timing of 0 for the Counter0 channel I got no data for it in the data file. Why? I thought I'd get a column of gradually increasing numbers (with lots of data points where it stayed the same from one reading to the next).

6. Why does the data file and graph on the streaming sample work when there is no LJ_ioGET_STREAM_DATA request in that document? From the LJ User's Guide section 4.3.7 I don't see where any of the sequences in the sample are asking to receive the data back from the device. What am I missing here? What command in that sample file is returning the streamed data?

I'm very pleased with how it works (I now know exactly what speed my desk fan spins at! - it was a handy test subject). Now I'd like understand some more of the why's.

Thanks for your help.

Craig

Link to comment
Share on other sites

> 1. What determines the number of rows of data points that I get in the logging file?

Depends on how you have the logging set setup. If you have it set as All Data Points (aligned), then it depends on your data rate and the alignment threshold. When streaming we recommend setting the alignment threshold to 0. If you don't, the maximum log rate is pretty much determined by the alignment threshold itself, with extra data thrown out.

- Timings are all set to 0 except for Channel0 is set to 1.0. Resolution is set to 16, and the clock to 750 Hz.

- I am streaming Counter0, AIN0, FIOx (i.e. channel 193), and a virtual channel called RPM that's calculated from the Counter0 data, in Counter0's Event tab.

Is RPM a virtual channel or a test channel? Virtual channels can be hard to log unless you are using an export set. When thing to note about channel events is that they aren't triggered on every data point when you are streaming, but rather on every packet. The packet size will vary on the total number of streaming channels. I'd have to look up the exact calc, but I believe its 16/number of streaming inputs, but if its not divisible (i.e. you are streaming 3 or 5 channels), the packet size will vary with each packet. The reason we do it on each packet is that the scripting isn't fast enough to process it on every data point when stream rates are high. For that matter, I'm not sure an event can keep up above maybe 5ksamples. Instead you should process the data after the fact.

- This line is in the streaming sequence (as based on the sample)

Device.LabJack.AddRequest(Var.d_number,"LJ_ioPUT_CONFIG","LJ_chSTREAM_SCAN_FREQUENCY",1000,0,0).

- I understand that a "scan" is one read through of all the data (i.e. one row of data in the output file), and a "sample" is a single piece of data (i.e. one "cell" of data to use Excel terminology). So I would read this to mean scan all the channels 1000 times per second. So 1000 rows of data per second. Is that correct?

Yes this is correct, you should get 1000 rows a second.

with all off the above settings, I get one row of data for every 0.002 seconds (so 500 scan per sec). The data file has 5 columns (TheTime, AIN0, Counter0, FIO0, RPM). The first two columns are full of data, the last three only have data points every 1.0 seconds (as expected with Counter0's 1.0 sec timing).

I'd have to see your document to see why, but most likely its the alignment threshold.

3. When the logging file time alignment was set to 0.05 sec, the data file only contained one row for every 0.05 seconds, rather than one for every 0.001 sec as I was expecting. When I changed the alignment threshold to 0.001 seconds, I ended up getting a data file with one row for every 0.002 seconds. Is it correct that the alignment threshold needs to be no more than desired scan timing?

What you see is expected. When streaming set the align threshold to 0. Align threshold is for things like the U12 where if you read 8 analog inputs, you get them in blocks of 4 separated by about 20ms. DAQFactory assigns the exact time to both blocks, so without the align threshold, you'd get two different rows in your logging set. When streaming, all data has the same time, so you want an align threshold of 0. The reason you see data every 0.002 with an align threshold of 0.001 is that its a +/- threshold.

4. How many "channels" is that? Is channel 193 a single channel or is it 16?

Why would it be 16? A channel, in terms of max 16 channels in express, is a row in the channel table.

5. When I used a timing of 0 for the Counter0 channel I got no data for it in the data file. Why? I thought I'd get a column of gradually increasing numbers (with lots of data points where it stayed the same from one reading to the next).

When you stream the counter in DAQFactory it shows up as an analog channel. This is because of the way the labjack UD is written. You had to specify a channel number when you told it what to stream, and thus DAQFactory only knows it as an analog input, not a counter. Within the UD its treated as a channel. The DAQFactory part was written to be flexible so we didn't have to change the DAQFactory driver every time a new special channel was created on a labjack device. So, you should make your Counter0 channel, A to D channel #210 and it should receive the streaming data. You shouldn't make a separate Counter I/O type channel, as this will query the channel separately, and is probably why you aren't seeing all the data you expect.

6. Why does the data file and graph on the streaming sample work when there is no LJ_ioGET_STREAM_DATA request in that document? From the LJ User's Guide section 4.3.7 I don't see where any of the sequences in the sample are asking to receive the data back from the device. What am I missing here? What command in that sample file is returning the streamed data?

None. DAQFactory handles this automatically, putting the data into the appropriate channels automatically. You should never have to call GET_STREAM_DATA. This is actually one of the few areas where DAQFactory script differs from the commands described in the LJ user's guide. Its done this way mostly to make it easier for you and because its much more efficiently done in C by DAQFactory then with a user script.

Link to comment
Share on other sites

4. See the end of Section 2.9.0 (just before 2.9.1). Channel 193 returns a single value that contains the state of FIO and EIO. Bits 0-7 of the value correspond to FIO0-FIO7, and bits 8-15 correspond to EIO0-EIO7. The following topic might be useful:

http://www.labjack.com/forums/index.php?showtopic=1006

5. Make sure you enable Counter0 before you start the stream.

Link to comment
Share on other sites

When streaming we recommend setting the alignment threshold to 0.

That did the trick. Worked great with a 0 alignment.

Is RPM a virtual channel or a test channel?

It's a Test channel. Before your reply I didn't understand the difference between those two.

The reason you see data every 0.002 with an align threshold of 0.001 is that its a +/- threshold.

OK, that makes sense.

Why would it be 16? A channel, in terms of max 16 channels in express, is a row in the channel table.

My understanding was that channel 193 returned the values of all 16 of the digital I/O (FIO0, FIO1, etc). And each FIO does take up one row in the channels list. That was why I thought it might represent 16 channels. But they're only one bit each, so it makes sense that all of them together is just one channel for streaming purposes.

So, you should make your Counter0 channel, A to D channel #210 and it should receive the streaming data. You shouldn't make a separate Counter I/O type channel, as this will query the channel separately, and is probably why you aren't seeing all the data you expect.

I had Counter0 as I/O Type: Counter, Channel: 0, Timing: 1. That worked for normal operation, but did only report the Counter0 value once per second. When I changed it to I/OType : A to D, Channel: 210, Timing: 0, I get the count on every scan. Can you explain why to use the I/O Type A to D instead of Counter? Is that the correct approach any time when using LJ counters in DF, or just in streaming mode?

None. DAQFactory handles this automatically, putting the data into the appropriate channels automatically. You should never have to call GET_STREAM_DATA.

Good. I like automatic!

Thanks for all your help. The support from DF and LJ is fantastic.

Craig

Link to comment
Share on other sites

I had Counter0 as I/O Type: Counter, Channel: 0, Timing: 1. That worked for normal operation, but did only report the Counter0 value once per second. When I changed it to I/OType : A to D, Channel: 210, Timing: 0, I get the count on every scan. Can you explain why to use the I/O Type A to D instead of Counter? Is that the correct approach any time when using LJ counters in DF, or just in streaming mode?

It only applies to streaming mode and its because of the way the Labjack UD works. It treats all streaming as an analog channel, but uses magic numbers to select other channels. So, 210 does the counter, 193 does the digitals, etc. Although DAQFactory puts the data in the right place for you, it does not know that 210 is counter, or 193 digitals because the LabJack guys may change this or add new ones, so by not fixing it in our code, we are always up to date.

This is also why 193 is only one channel. DAQFactory doesn't know you are looking at 16 digitals packed into a word.

When you are not streaming and simply reading the counter (or the digitals for that matter), you should use the appropriate I/O type and not A to D.

Link to comment
Share on other sites

Archived

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