LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer waveform generation

Hello, I am using an MSeries DAQ board. I have to implement a waveform generator. The main problem is hor to define the size of the buffer when I am generating more waveform continuosly. Now I calculate the maximum commom divisor(MDC) among the frequencies, then I divide the maximum sample rate by the calculated frequencies (MDC). In this way I am sure to have a size of the buffer that is a multiple of all the frequencies. The problem is that when two frequencies are very close the MDC is very very low then the buffer size  is very large.
Do you have any suggestion? Could I use for each waveform different sizes of buffer ?
 
Thanks in advanced.
 
 
0 Kudos
Message 1 of 6
(4,043 Views)
For continuous generation -- no, you won't be able to change the buffer size on the fly.  The actual size of the output buffer will remain constant.  You have a fairly difficult problem here and I don't know of a simple solution.  A couple alternatives:
 
1. If possible, don't advertise it as a generator of arbitrary frequencies.  Only allow generation of preset frequencies that are integer divisors of sampling rate.  I doubt you'll be able to get away with this approach though.
 
2. Plan to write code that continuously "babysits" the generation task.  In this approach, the data acq buffer doesn't need to be sized to hold an exact full cycle of your waveform, it should instead be sized much bigger.  The babysitting job is to monitor the task to know when to keep writing N-cycle chunks of your waveform down into the write buffer.  To support higher freqs and more samples per cycle, you'll need a bigger output buffer to accomodate the overhead of your "babysitting."
   It'd be best to always write chunks that start and end at a zero crossing.  Then if the waveform freq setpoint is changed,  you simply write the new waveform down, knowing that the frequency change will happen at a zero crossing and thus not make an abrupt output voltage spike change due to phasing issues of the different freqs.
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 6
(4,033 Views)

Thanks a lot, one question more. Probably my doubts come from my bad known of how the DAQ manages the buffer. Do I have one buffer for each channel or the channels share the same buffer?If the first hipothesis is true I could set the size of each buffer in order to contein one cycle of the waveform, then I could use the same same sample rate (for example the maximum sample rate) for all the channels. But now rise in my mind another doubt: Size buffer1= 100 and size buffer2= 110. It scans the buffer at the maximum saple rate, after 100 saples the buffer1 ends. What happen at sample 101? It continues to scan the buffer2 and restarts from the begin of buffer1?

Sorry for the confusion.

 

Thanks again.

0 Kudos
Message 3 of 6
(4,030 Views)
You only get 1 buffer for all AO channels to share.  So the rest of your questions don't really apply.
 
However, your post reminded me of a simpler solution.  I didn't think of the fact that you can change the output rate on the fly for an analog output task.  There'll still be some tradeoffs to make though.  For example, if you set your AO sample clock at a max of 1 MHz and you want to maintain a buffer that defines at least 20 samples per sinusoid cycle, your maximum analog waveform frequency will be 50 kHz.  You'll need to tradeoff the amount of digitization error due to small #'s of samples per sine wave vs. the frequency limitations you get with large #'s of samples per sine wave.  Still, this is much simpler to implement than the "babysitting" solution and will give you a more nearly continuous set of possible output frequencies to choose from than the "use a big buffer containing integer #'s of sine cycles" solution I described earlier.
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 6
(4,026 Views)

Hello,

I'm trying to do the exact same thing.   Generate multiple analog outputs waveforms with user controlable frequency.  This problem seems trival in labview, however; much more harder to understand in ANSI C.

With ANSI C, is it possible to arrange the output buffer data for different buffer sizes per channel.  For example, 100 samples for A01 buffer and 200 samples for AO2 buffer.
Can this be done with an Array of different sized arrays?

How do I write the  DAQmxWriteAnalogF64 function in C to emulate the Labview DAQmx Write (Analog 1D Wfm NChan NSamp) VI? 

Thanks in Advance,

Francis
0 Kudos
Message 5 of 6
(3,920 Views)
Instead of using an old thread, why don't you post a new question to the Multifunction DAQ forum where you will have a better chance of getting a non-LabVIEW answer.
0 Kudos
Message 6 of 6
(3,912 Views)