06-23-2008 02:00 PM
Hi, I need help with this one:
I'm planning to generate a sequence of analog waveforms continuously. Every waveform has a different pattern. While they were digitized they were sampled at different sampling rates so in order to reproduce them correctly I have to change the sample rate in the DAQmx timing configuration function. Also, the length of the files (samples) to play is different so the Samples to generate also changes in between the waveforms.
I’d like to reconfigure this two parameters (sample rate and # of samples to generate) on the fly (without stopping the task), is this possible?
I’m currently using continuous generation with no regeneration. I’m also installing a callback each time SamplestoGenerate reaches certain value to re-write the buffer with new the samples but the problem is that the number of SamplestoGenerate varies on each new regeneration and I don’t know how to change it dynamically while the AO is being generated:
DAQmxSetWriteAttribute(gTaskHandle, DAQmx_Write_RegenMode, DAQmx_Val_DoNotAllowRegen);
DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandle,"",samplerate,DAQmx_Val_Rising, DAQmx_Val_ContSamps, SamplestoGenerate));
I’m using Labwindows CVI/8.1 and a NI USB 6221 with the latest DAQmx driver
Any help will be appreciated.
06-24-2008 01:21 PM - edited 06-24-2008 01:21 PM
06-24-2008 02:21 PM
Hi Chris, as usual thank you for your reply.
Your oversampling idea sounds good but unfortunately in my case the waveforms have been already oversampled! so oversampling and oversampled waveform is not a choice to me . Let me explain you a little more in detail what I’m trying to do:
Problem: I need to continuously generate a sequence of different waveforms. The characteristics of each waveform is quiet different in terms of the sampling rate used to do DAC and the number of samples to generate per waveform. In general terms, I won’t be playing the same waveform twice so I’m using FiniteSamps when configuring the timing of the task. I’m using the internal clock of the device as clock source (I'd really like to use the internal clock of my DAQ board, this makes the hardware simpler).
The sampling rates after oversampling are in the range of 1 KHz – 10 KHz (original sample rates are in the range of 250Hz to 500 Hz).
The number of samples can vary between 5000 up to 11000000. (5 sec to 30 min)
Example:
Generate Waveform1 (5.7 KHz, 55000samples)àWaveform2 (4KHz , 5000000 samples)àwaveform3 (4096Hz, 11000000samples)à………waveform n. stop
As you can see, playing time can vary from min to hours when I play a sequence of waveforms.
If possible I don’t want to have silent periods while transitioning from one waveform to another, so the following waveform generation should start as soon as the previous one is done.
Since each waveform is different I have a function that reads the sample values and set a big array accordingly: Readrecord ( ). This function works ok.
I’m thinking that on every generation of the new waveform I have to reconfigure the sampling rate and the number of samples to generate.
If there is no other choice than stopping and starting the task over and over it’s fine as well. The problem is that I don't know how to accomplish this programmatically. Attached is part of the code I've written so far. I'm installing callback called DoneCallback2 in order to stop, clear and then re-start the analog generation once N number of samples has been generated on the previous task. The Readrecord() function reads a file and forms an array called Rawchan1 for the analog output.
For each time the AnalogGenAuto () runs I also generate a digital pulse to indicate the beginning of a new waveform.
My problem is that I can't get the second analog generation to start even though I can see the second digital pulse to be generated correctly once the first generation has reached its end (this tells me than the Donecallback2 function is working properly). Something is wrong with the logic of my program and I don’t know what.
Any help will be appreciated,
Thanks,
06-25-2008 11:55 AM
06-26-2008 11:14 AM
Hi Chris,
I reconfigured the code following your suggestions and now it looks like the file attached. It seems to work now. The reason why the second analog generation wasn't working is because there was a DAQmxClearTask(taskHandle) command after the error check in the Donecallback2. I did not catch that error until yesterday. Now my code seems to be doing what I want it to do.
Thank you very much for your help.
Cheers,
Giovanni
06-27-2008 10:58 AM