Streaming from the sound card


steph_tsf

Recommended Posts

Hello,

Has anybody succeeded in using the sound card of the PC as data provider for DAQFactory ?

I know this is somewhat off-topic but it would be a nice 49.99 $ add-on to LabJack U3 driver.

This would enable LabJack U3 (limited to 100Hz sampling rate) cooperating with other signals that are an order of magnitude faster.

My application requires about 10 slow signals to be displayed and measured with a sampling frequency of about 20 Hz (OK for LabJack U3), plus one oscilloscope display, dealing with two other signals sampled at 8000 Hz (not OK for LabJack U3).

At the moment I am using SpectraLab 4.32, using the sound card of the PC at a sampling rate of 8000 Hz. Left and right audio are displayed like an oscilloscope.

So, I have both SpectraLab 4.32 and DAQFactory running in parallel, this is unconvenient and creates problems in synchronization and data logging.

What I need is that DAQFactory does recognizes the PC audio subsystem as a potential data provider showing into the "Device Configuration" tab.

In DAQFactory you select "PC audio input" then you get a configuration screen : sampling frequency (from 4000 Hz till 48000 Hz) and lenght of vector (from 1 sample till 65536 samples).

Say a sampling frequency of 8000 Hz and an lenght of 256 samples.

Then, in DAQFactory channel table view, you would get the corresponding channel.

The "timing" value is the period at which you request a new vector to be imported.

Say 0.1 second.

I do not care about the fact that there will be "gaps" in the acquisition.

I do not care if the user is incorrectly requesting a new vector while the old one is not yet completely aquired, this case arising when the sampling frequency times the lenght of the vector is less than the "timing" value.

Then in DAQFactory measurement page, you would display this vector as an ordinary 2D Graph.

Refreshed every 0.1 s (if the PC is fast enough to cope with that).

In summary, I only need this scheme as a "quick and dirty" way to get intermittent snapshots of fast waves to be displayed on DAQFactory measurement page.

In my car ignition diagnosis and measurement application, this would be :

- sampling the left and right audio at 8000 Hz

- left = negative side of ignition coil

- right = capacitive probe on high voltage wire or current probe on high voltage wire

- at the driver level : sampling left and right audio at 8000 Hz and lenght of vector equal to 256 points

- hence getting an intermittent snapshot of 256 points representing 30 millisecond of signal

- In DAQFactory channel table view, requesting this vector to be acquired every 100ms

- In DAQFactory measurement page, displaying this vector as an ordinary 2D Graph

Then, but this is beyond considerations about a PC audio driver, In DAQFActory application, some conditional statements and actions enabling automatic synchronization (having the spark pulse always left justified), automatic time base adjustment (always getting a few pulses on the snapshot), and automatic wave analysis.

This would be quite solid, and low cost, isn't ?

I think this would extend LabJack U3 market.

People will understand they get the opportunity, as a bonus, to get snaphots of fast waves.

And when they need to aquire and get representations of DC and slow-varying signals, they still will need LabJack U3 as this cannot be done using the PC audio subsystem.

I think this would help people understanding it is better to use the PC as data acquisition tool, even for faster signals, so then there will be more people willing to pay more money in getting DC-precision fast aquisition modules containing 16-bit A/Ds providing up to 500 Khz sampling rates like for instance the AD7686 from Analog Devices that can be daisy-chained to a USB2 enabled microcontroller.

So you get a USB2 powered DC-coupled 4-channel aquisition box for less than 300 $ retail price.

Bipolar single-ended inputs with 1 Volt sensitivity (you need to generate a -5V supply inside the box).

http://www.analog.com/IST/SelectionTable/?...on_table_id=201

Say a LabJack U4 that will integrate in DAQFactory.

Regards,

Steph

Link to comment
Share on other sites

Hello LabJack Support,

Thanks for your reply.

Good news indeed !

So I just went into LabJack U3 User Manual, streaming section.

Okay, now I understand that analog acquisition at 10000Hz sampling rate is possible using streaming.

Okay, I agree this would be perfect for my application.

But, and this is of practical importance, how to setup or configure this under DAQFactory ?

Remember I would like to get an intermittent oscilloscope view in a 2D graph, something like 128 or 256 data points represented.

And get this 2D graph refreshed every 100 millisecond.

In DAQFactory.

Then if you can help me adding automatic synchronization (read the data set and try justifying the peak on the left side of the 2D graph), that would be lovely.

Then if you can help me adding automatic timebase management (through horizontal resize and/or through change of sampling frequency), in order to always display 6 such peaks in one 2D graph, that would be lovely too.

Best regards,

Steph

From Brussels

Link to comment
Share on other sites

To get you started, I've attached a simple stream example of 4 channels.

To get the peak along the left side of the graph you should calc the max of the scan, get the time of that point, and set the ScaleFrom to that time and the scaleto to that time plus whatever time width you want. So, for example, you might put:

GetTime(Max(AIN3))

for ScaleFrom

and

GetTime(Max(AIN3))+1

for ScaleTo to get a graph with just one second width. To put the max on the right side, switch it and do -1 instead of +1. Note that you'll need to uncheck "Time Width" to enable the scalefrom/scaleto in the graph.

I'm not quite sure what you want with the "automatic timebase management", but check out the shifttime() function, which would allow you to adjust the different traces in time. You would use it in the secondary traces. So if you want all the max peak of two different traces to appear along the left side of the graph where the maxes may occur at different times you would start with the code I mentioned above to set the X axis scaling, and then (assuming your other channel was AIN2), you'd create two traces. The first trace would have a Y Expression of just:

AIN3

the second would use shifttime to move the max of AIN2 to the same time as the max of AIN3:

ShiftTime(AIN2,GetTime(Max(AIN3)) - GetTime(Max(AIN2)))

Note, of course, that the time axis is only the time of the datapoints of AIN3, though the deltaT will be the same. We didn't scale time, we just shifted it to align the peaks.

Finally, lets say you want the peak to appear just to the right of the left axis so you can see the leading edge of the peak. In this case, just subtract a little from the scalefrom and scaleto:

ScaleFrom:

GetTime(Max(AIN3)) - 0.1

ScaleTo:

GetTime(Max(AIN3)) + 0.9

Then, just to top it off, if you then wanted to mark the max point (which would then be 0.1 seconds from the left axis), you could use a line annotation to put a dashed line. The line annotation would have an expression of:

GetTime(Max(AIN3))

and you'd select the Bottom Axis.

I guess the key point that I never mentioned is that when you do Max(AIN3), this returns the max of AIN3, but it also keeps the time of the max in the value as well. DAQFactory keeps time associated with values, and to retrieve the time portion of the value, we use the GetTime() function, so GetTime(Max(AIN3)) returns the time of the max point of AIN3. This can be used for Min as well. The rest of this is just doing math on the time, remembering that time in DAQFactory is just a number that corresponds to the number of seconds since 1970, so it can easily be added or subtracted. ShiftTime() does this to the time portion of a value, returning that same value with the time shifted by the given amount.

Finally, I attached my expansion on the stream simple document that shows this peak alignment working. I didn't have any input and so the values were just floating around 0.15, except of course when I touched the inputs, which would generate a nice peak. You may have to adjust the y scaling to better see your peaks. Just double click on the left axis.

As you can see, once you get a little experience with the various functions of DAQFactory, it is real easy to manipulate data to get what you want.

U3_Stream_Simple.ctl

U3_Stream_Simple_Peaks.ctl

Link to comment
Share on other sites

Gush you saved my day...

Starting from the manual I was stuck with non existing "Command" drop downs in the channels...

I tetsted with 1000 Hz with my old USB1.1 600 MHz Pentium II Vaio, and got some noisy measurements.

Appearantly the U3 or my notebook produces acoustic noise when streaming....

The measurements using LJDivider with only one channell connected to open cables revealed some noise- here is the distribution:

Voltage 0,005 0,01 0,015 0,02 0,025 0,03 0,035 more

Counts 5312 4287 2099 493 975 1112 46 1

Next will be to test how far I may go regarding frequency and be patient to wait for a Windows Mobile Solution for this streaming....

cheers

Gerfried

Link to comment
Share on other sites

To evaluate noise, you should use a solid voltage, rather than an open connection. An open connection is not zero volts, but rather is undefined (Section 2.6.3.8). Take the constant 3.66 volts from the REF/DAC1 pin and run that through your LJTick-Divider. Or if you are using a differential input right on the U3, connect both channels to GND.

We do have Windows Mobile drivers for the U3. See the PocketPC archive on the U3 downloads page.

The voltage range of a single-ended input on the U3 is about 0-2.5 volts, so if you are using a single-ended input you will see a minimum reading of about 0. What is the voltage range of your signal, and how do you have it connected?

I tried the example "U3_Stream_Simple.ctl" provided by Azeotech above, and it does seem to stop streaming for me when I click the "Stop" button.

Link to comment
Share on other sites

Hello,

many thanks.

Yes this happens if you are used to use the U12 plug and play and change to the U3.

The problem is a little more complex and I rather think that the existing measuring setup is not the best one.

I only need the times between sign changes of the voltage- voltage is up to 20V AC varying voltage and frequency.

So far I had measured with 300Hz using the U12 and calculated the sign changes of the voltage afterwards in simulink doing the filtering but now I could do this with 2 kHz but I have to put away the LJDivider which I now use because it outputs only positive voltage...

I guess I have to connect the wires to 2 channels to measure a differential signal...

But may be I will better use counters - but they need to record the time of the count.

thank you

gerfried

To evaluate noise, you should use a solid voltage, rather than an open connection. An open connection is not zero volts, but rather is undefined (Section 2.6.3.8). Take the constant 3.66 volts from the REF/DAC1 pin and run that through your LJTick-Divider. Or if you are using a differential input right on the U3, connect both channels to GND.

We do have Windows Mobile drivers for the U3. See the PocketPC archive on the U3 downloads page.

The voltage range of a single-ended input on the U3 is about 0-2.5 volts, so if you are using a single-ended input you will see a minimum reading of about 0. What is the voltage range of your signal, and how do you have it connected?

I tried the example "U3_Stream_Simple.ctl" provided by Azeotech above, and it does seem to stop streaming for me when I click the "Stop" button.

Link to comment
Share on other sites

Note that a differential input on the U3 can handle a signal where the positive input is less than the negative input, but no line can be more negative than -0.3 volts compared to GND.

Check out the LJTick-Divider datasheet, as it is pretty easy to modify the LJTD so that it handles +/- 10 volt signals.

Link to comment
Share on other sites

Thank you -Since I only want to capture the frequency (timespan between sign changes of the signal) I guess that the measuring range is not relevant. I hope I will not ruin the U3 with 20V.

But I'm in need of a DAQFactory streaming example using timers (duty cycle?) using streaming mode if necessary?

thanks a lot

gerfried

Note that a differential input on the U3 can handle a signal where the positive input is less than the negative input, but no line can be more negative than -0.3 volts compared to GND.

Check out the LJTick-Divider datasheet, as it is pretty easy to modify the LJTD so that it handles +/- 10 volt signals.

Link to comment
Share on other sites

If you check Appendix A of the User's Guide, you can see that the maximum input to an FIO/EIO line to avoid damage is +/-10 volts (FIO) or +/-6 volts (EIO). So 20 volts is exceeding the voltage limits and risking damage. I recommend you put a 10k resistor in series with each analog input to provide a lot more protection.

The UE9 uses the same driver as the U3, so UE9 examples are often an additional resource you can use for help. For some general duty cycle example code, see the example "UE9_PWMDutyCycle" in the VC6_LJUD archive. For some timers in stream code, see the example "LJUD_VB6_UE9_StreamTimer" in the VisualBasic_LJUD. We will have to see what Azeotech has for DF examples.

Link to comment
Share on other sites

If you check Appendix A of the User's Guide, you can see that the maximum input to an FIO/EIO line to avoid damage is +/-10 volts (FIO) or +/-6 volts (EIO). So 20 volts is exceeding the voltage limits and risking damage. I recommend you put a 10k resistor in series with each analog input to provide a lot more protection.

Many thanks for that cautious words.

The UE9 uses the same driver as the U3, so UE9 examples are often an additional resource you can use for help.

No chance - I won't code - I have just failed to install Visual Studio - also the project files are for a loder version than C#2005 - so it simply is far to complex to do so...

For some general duty cycle example code, see the example "UE9_PWMDutyCycle" in the VC6_LJUD archive. For some timers in stream code, see the example "LJUD_VB6_UE9_StreamTimer" in the VisualBasic_LJUD.

Thank you - I doubt that I will manage to come up with a solution using those examples...

We will have to see what Azeotech has for DF examples.

unfortunately they have also no Windows Mobile support yet...

Summarising I kindly ask to provide similar support for the U3 both for Windows 2000 and Windows Mobile as was available for the U12.

- Logger

- Stream

- Scope

many thanks

Gerfried

Link to comment
Share on other sites

If you check Appendix A of the User's Guide, you can see that the maximum input to an FIO/EIO line to avoid damage is +/-10 volts (FIO) or +/-6 volts (EIO). So 20 volts is exceeding the voltage limits and risking damage. I recommend you put a 10k resistor in series with each analog input to provide a lot more protection.

I was using the LJDivider to be able to use the higher voltages and it worked - but of course you cannot measure periods using the timer because the input voltage becomes to small in the case of varying voltages 0-20V 0-150 HZ.

As having written in a different thread removing the LJ-Divider resulted in odd mesurements.

Gerfried

Link to comment
Share on other sites

Archived

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