08-08-2014 11:34 AM
Hello all,
I am trying to create analog output from my NI 4461 Analog I/O card and change the voltage for each iteration of my loop. I initially thought I would use the DAQmx commands to create the channel, configure timing, write the waveform, play it, etc. without a task. However, I would run my code, it would show no errors, yet it wouldn’t change the output voltage.
I did not initially use a task because I didn’t think the voltage level could be changed if I used a task for a set voltage. However, I created a task and ran it in NI MAX and I received the correct voltage from my analog output signal so there is nothing wrong with any equipment or connections.
I guess my basic question is: Can I create a task and then adjust the analog output voltage for each iteration of the loop? It seems so simple to do this but I haven’t been able to figure it out.
I attached my code. It also sets a power supply to a voltage and reads it in the first part of the case structure as well as saves values in a .csv file in the second part. Everything works great but the analog output. Sorry for the 2 snips, I don’t think there is a zoom button in labview.
Thanks!
Solved! Go to Solution.
08-08-2014 11:48 AM - edited 08-08-2014 11:48 AM
Since you are doing a single sample at a time, your are just going to write out either the first or the last sample (not totally sure which one right now). I'm not totally sure what you want. If you just want to play your read waveform, you don't need a FOR loop. You do need to tell it multiple samples instead of single sample.
But if you just want to write your elements in that array constant, that is quite simple.
08-09-2014 05:43 PM
By all means, create a Task in MAX and test it. If it does what you hope, you're 95% done. Here's a snippet to illustrate how simple it is to do DAQmx stuff with MAX tasks -- this is basically your entire program (of course you need some timing, and need to wire in the data, and need to stop the While loop, but those are "details" ...).
You'll notice a constant wired into the Start VI. If you've defined a MAX Task called, say, My AO Task, you should be able to click the drop-down arrow and have "My AO Task" appear. It will include the channel you defined for the task, the device, the sampling time, etc.
This gets even nicer if you are doing Analog Input, because you don't need to define all the channel parameters on your block diagram (such as Max, Min, coupling, triggering, etc). The down side, of course, is you do need to have the MAX task defined, but you can also pull the Task itself into your Project (and thus make it "portable").
BS
08-11-2014 07:41 AM
I want to play my .wav file at those different voltage amplitudes. If the voltage amplitudes get placed in the input labeled "data" of the write subvi like your example shows, then where would the .wav file get wired to?
08-11-2014 07:51 AM
08-11-2014 08:05 AM
There is db in the .wav file that can be converted to Vrms, but I want the Voltage output to the speakers I am driving to be those set values. I want to drive the signal at different voltages.
08-11-2014 08:12 AM
If you are playing a .wav file, then you need to consider a few more things, not the least of which is decoding the file to get out (a) the sampling rate (the rate at which the data were acquired, which will probably also be the rate at which you want to play the data back) and (b) the digital values of the waveform(s). The plural is because there may well be more than one channel saved in the file (e.g. stereo) -- I'm not an expert on this format.
Suppose you know the playback rate (say, 44KHz) and have a single channel of, say, I16 data to play back. First, you probably want to configure MAX to allow you to output data at 44KHz (assuming your D/A board is capable of such a rate) and you probably want to output chunks of data (maybe 10000 points at a time) continuously (meaning "send the next bunch of data as soon as the first bunch has been sent"). Build this into your Task so you don't have to mess with it in your VI.
Now all you have to do is have a loop that (a) gets an array of 10000 data points from your .wav file "as fast as practical", (b) feeds these chunks to the D/A converter's "Data Write" input (having changed it from 1 channel 1 sample to 1 channel N samples) and (c) keep doing this until all the data have been played.
Now you have the following interesting situation -- you have one process, "Getting the data points", going at one speed, and another, "Using the data points", going at another, and don't want there to be "gaps" between them. You hope that the process of getting the data can go faster than the process of using it (which is another reason to process 10000 points at a time, instead of one at a time).
This is an example of something called the Consumer-Producer Design Pattern (look for Consumer Producer, or possibly Producer Consumer, in LabVIEW Help, LabVIEW Examples, or on the Getting Started "Welcome" page under New Projects or New VIs). The key step is that you do the Producer (of the data) in one loop (such as reading the .wav file and packaging the data into arrays of 10000 points) and you put the Consumer (sending the data to your D/A converter) in a parallel While loop, running independently of the first, connecting the two using a Queue into which the Producer places the data and from which the Consumer extracts it.
BS
08-11-2014 08:37 AM
The .wav file I have is 30 seconds long and has the format: 48 kHz, 16 bit, mono.
I understand what you're saying involving MAX. If I build that into my task, then when does the .wav file come into play? And what about changing the output voltages? Can I change that after I configure it in the task?
08-11-2014 09:13 AM
The Output Voltage setting depends on your DAC device and on what you have connected to it. Suppose you have a 16-bit DAC that is capable of putting out voltages in the range ±10v, and you have an audio amplifier hooked up to it that also goes ±10v. In this case, you should tell MAX that your D/A output channels are ±10v so that you maximize the signal-to-noise of your output. If you now send the number 32767 to the DAC and measure the voltage, it should be +10, while if you send -32767, it should be -10.
What if your amplifier only takes 0 to 5v? You should set the DAC to match it (so you don't send -32767 and "cook" the amplifier that is not expecting -10v). There are good white papers on NI's site that discuss handling Analog signals that can give you more information about such things as signal conditioning, filters, amplifiers, etc.
BS
08-11-2014 09:17 AM
Sorry, I didn't answer "When does the .wav file come into play". See my previous post -- you read the .wav file, it gives you numeric 16-bit data at 48KHz. These are the 16-bit numbers that you send to the DAC (at 48KHz) where the DAC converts them to voltages (with -32767 being the most negative voltage to which the DAC is configured and 32767 being the most positive).
BS