LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

output sine wave signal usb 6009

Hi,

 

I am using a triaxial accelerometer to detect position in three planes during certain movements. The deciphered position is then compared to a path that is user generated and if it falls with in the limits of the path then the boolean returns true. However when outside of the path a sine wave signal with low voltage and frequency around 150Hz is to be output to a speaker (buzzer) to correct for the error in that respective plane. For instance, if my hand is at 3in in the x direction but should be between 1.5 and 2.5 in a signal will be sent to the buzzer that corrects the x-position. I am utilizing a usb-6008/9 and am aware of its software dependent output limitations of 150Hz. The output voltage only needs to be around 2.5V and I understand the 6008 can output up to 5V. I am trying to do this simple task and have looked at the example VIs for voltage output with DAQmx but I keep getting multiple errors when trying to use a sample clock and all the functions surrounding it. Any help would be appreciated. I have had a field engineer look at my setup and said that the tools I am using would suffice for the data I am trying to input and output. 

 

I have attached my simple output code.

 

Thanks,

Ben

0 Kudos
Message 1 of 17
(6,773 Views)

Ben,

I've got a USB-6008 that I just plugged in. You can only set the analog output to 1 sample (on demand). That means you can only output 1 sample to the Analog output on each loop iteration. (BTW, you do need to put your DAQ Assistant in a while loop to make it continually run). The timer you put in that while loop will control the speed at which samples are written to the analog out

 

Eric

0 Kudos
Message 2 of 17
(6,755 Views)

Thanks Eric,

 

First of all thank you for your quick response and secondly I apologize for my mediocre level of LabView knowldege, thanks in advance for bearing with me. Do enclose the entire process in a while loop or just the Daq Assistant. For the timer would I use a sample clock (DAQmx timing.vi) along with the other DAQmx modules (start/stop task etc.)? I assume if you are pointing me in this direction then one of the examples found in outpu/voltage would be useful although I have tried to use them with no luck. Perhaps you could point me in the right direction as to which one to use for my problem.

 

Also my updated Vi is attached

 

 

Ben

0 Kudos
Message 3 of 17
(6,751 Views)

Ben,

In this case you would want all the code in the loop. What would happen if you didn't have your frequency and amplitude controls inside the loop is they would be fed from outside of the loop and you couldn't change them once it was started. Putting controls and indicators inside of loops means they are read or updated on every loop iteration. This can be very processor intensive, but for your beginning example it's fine.

 

The way the express DAQ Assistant works is that it eliminates the need to configure all the other DAQmx functions like start task, write/read, stop task. It's meant for quickly setting up and acquiring/generating signals. Alternatively, all the settings within the DAQ Assistant can be configured using the other functions on the DAQmx pallette. More developed LabVIEW applications probably rarely use the DAQ Assistant, but for this kind of simple stuff it's easy and works well.

 

The Wait function is controlling how often your loop iterates. In the edited VI attached, it's happening every 10 ms. If you don't have a Wait function in your loop it will run as quickly as it can. Try it and watch your CPU chart in task manager go to 100%. When choosing how often a loop should iterate, the general rule is to make it run no faster than it has to.

 

Another note about loop timing: when you set up a loop for acquisition, the loop speed can be dicated by the data acquisition depending on how you have the acquisition set up. If you were doing data acquisition that was limiting your loop speed to 100 ms and you put a Wait function in your loop set to 1 ms, the loop would only iterate every 100 ms. The Wait function wouldn't be doing anything in that case. It's like a governor that tells the loop to never iterate faster than the time you wire to its input.

 

Eric

0 Kudos
Message 4 of 17
(6,738 Views)

Eric

 

I just tried to implement your edited set up. I tried running the loop with no wait time and the cpu clocked in at 30% usage so it would be fine from that standpoint. However I can't seem to get an output to my speaker that I'm using when I select an amplitude of 5 which I assume to be the voltage output and a frequency of 150Hz and lower. I have the output terminal (AO0) wired to the positve end of the speaker then ground connected to the analog ground (after i tried with digital ground; not that there is a difference). Is my wiring correct because thats the only thing I can think of to be wrong. 

 

Ben

0 Kudos
Message 5 of 17
(6,714 Views)

Ben,

I don't know the power specs off the top of my head for the USB device you are using, but it's certainly not enough to drive a speaker. Yeah, it can output 5V, but not with any kind of appreciable load. You need an amplifier if you want to be able to drive a speaker.

 

Eric

0 Kudos
Message 6 of 17
(6,704 Views)

Eric

 

Thanks, as soon as I posted I started putting one together. Ill let you know how it goes.

 

Ben

0 Kudos
Message 7 of 17
(6,702 Views)

You might reference this Wiki article on line level audio. The output impedence of a USB-6009 is 50 ohms. It can supply 5 mA at 5V. You might try a low voltage output from the USB device to a consumer audio speaker with line level input. Start with a low voltage sine wave less than 0.5V. An electrical engineer would have better advice than me on this.

 

 

http://en.wikipedia.org/wiki/Line_level

0 Kudos
Message 8 of 17
(6,692 Views)

I just looked back at the original post.  You want a sine wave at about 150 Hz.  The maximum SAMPLING rate of the USB-6009 AO is 150 Hz. The Nyquist theorem applies to signal generation in sampled data systems just as it does in data acquisition systems.  Thus you cannot generate any signal higher than less than 75 Hz.  At 75 Hz you get two samples per cycle which implies that you essentially have a square wave.

 

Typically you would need 8 or more samples per cycle to begin to simulate a sine wave.  That gets you down to less than 20 Hz.

 

You need to re-evaluate your requirements or get a faster data acquisition device.

 

Lynn

0 Kudos
Message 9 of 17
(6,687 Views)

Ben,

Crutchfield sells some really nice amplifier/sub-woofer combinationations. Put a couple of 12" subs in an enclosure, get an amp to drive them, and you're good to go!

 

Eric

0 Kudos
Message 10 of 17
(6,685 Views)