08-15-2005 10:39 PM
08-16-2005 08:54 AM
Hi Daniel,
Please also take a look at this link, someone else also has problem with no-regeneration mode Analog Output.
http://forums.ni.com/ni/board/message?board.id=250&message.id=13661&query.id=65563#M13661
Is it possible to output the waveform I attached?
Thx,
Rolly
08-17-2005 03:28 PM
Hi Rolly-
I agree with Alan's comment in the other thread- it doesn't seem that the error you are seeing is related to the non-regeneration setting but rather to something else in programming. However, based on the diagram you posted it seems that the durations at each voltage level are basically set.
If this is the case then the best method to avoid glitching and to avoid the necessity of continually writing buffer information "on the fly" is to write the entire buffer at the beginning and then simply clock it out. Is it safe to assume that the timing of your output changes is set and will not change? If so then this method is generally recommended for better results.
Thanks-
08-18-2005 03:57 PM - edited 08-18-2005 03:57 PM
Message Edited by Quantumbyte on 08-18-2005 04:17 PM
08-19-2005 12:29 AM
Hi Daniel,
Thank you for the advice, I did a little modification of your code to produce the 15Hz/2KHz sqwfm generation, please have a look at my code:
#include <NIDAQmx.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int main()
{
TaskHandle taskHandle;
int32 written;
float64 square_low_amp_data[100];
float64 square_high_amp_data[100];
int i,j;
//ADD code here to fill your arrays
for (i=0;i<50;i++)
square_low_amp_data[i]=-1;
for (i=50;i<100;i++)
square_low_amp_data[i]=1;
for (j=0;j<50;j++)
square_high_amp_data[j]=-5;
for (j=50;j<100;j++)
square_high_amp_data[j]=5;
DAQmxCreateTask("",&taskHandle);
DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(taskHandle,"",200000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
DAQmxWriteAnalogF64(taskHandle,100,0,10.0,DAQmx_Val_GroupByChannel,square_low_amp_data,&written,NULL);
DAQmxStartTask(taskHandle);
while(!_kbhit())
{
Sleep(33);
DAQmxWriteAnalogF64(taskHandle,100,0,10.0,DAQmx_Val_GroupByChannel,square_high_amp_data,&written,NULL);
Sleep(33);
DAQmxWriteAnalogF64(taskHandle,100,0,10.0,DAQmx_Val_GroupByChannel,square_low_amp_data,&written,NULL);
}
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
return 0;
}
However I notice from scope display, the 15Hz component of this sqwfm is not stable, it jumps randomly form 64ms to 78ms, as attached BMP. Could you please have a look? I think the Sleep() function is the reason behind, is there way to lock-up this component at 66ms(15Hz)?
Thank you very much,
Rolly
08-19-2005 10:15 AM
Hi Rolly-
I think you are definitely correct that the sleep function is causing the problem. Because you are not using non-regeneration the output waveform will begin to loop automatically if the end of a segment is reached before new data is written. In order to prevent this situation you need to make absolutely sure that you write to the buffer more frequently that it is emptied.
For instance, if your waveforms are composed of 100 points and your sample clock is running at 50Hz then you will be writing 2 seconds worth of data each time you write the information out to the buffer. You just need to make sure that you add data to the buffer more frequently than the time it takes to reach the end of the current data to avoid re-writing the same samples again. Decreasing or perhaps even removing the sleep command should aid in achieving this.
Hopefully this helps-
08-19-2005 10:43 AM - edited 08-19-2005 10:43 AM
Message Edited by Quantumbyte on 08-19-2005 10:46 AM