01-09-2011 02:36 AM
Hellow ,
i'm tying to create a sin waveform and i don't know if the way to create this wave is similar to creating analog normal analong volt output
this is what i did :
int AnalogOutputSin (double *freq,double *amp,char chan[256] ,double *offset)
{
int error=0;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};
float64 freqCast;
float64 ampCast,offsetCast;
freqCast = *freq;
ampCast = *amp;
offsetCast = *offset;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAOFuncGenChan (taskHandle, chan, "", DAQmx_Val_Sine, freqCast, ampCast, offsetCast));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Write Code
/*********************************************/
????????
DAQmxClearTask(taskHandle);
Error:
if( DAQmxFailed(error) )
{
DAQmxGetExtendedErrorInfo(errBuff,2048);
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
MessagePopup("DAQmx Error",errBuff);
return 0;
}
i dont know what tio write in the DAQmx Write Code section i looked for some examples but didnt find any.....
Solved! Go to Solution.
01-10-2011 11:49 AM
Hi Kobi Kalif,
The DAQmxCreateAOFuncGenChan is only supported with our NI ELVIS products. To create a sine wave using your PCI/PXI-6733 please look at this example:
Start»All Programs»National Instruments»NI-DAQ»Text-Based Code Support»ANSI C Examples»Analog Out»Genereate Voltage»Cont Gen Volt Wfm-Int Clk
This example creates a lookup table of values using the math.h library. Then this lookup table is read at the speed of the sample clock. By default it creates a lookup table of 1000 points and the sample clock is set at 1000 Hz. This will genereate a 1 Hz signal. The ratio between the sample clock and the number of points determines the frequency of the output. If you had a lookup table of 1000 points and a sample clock of 10000 Hz, the frequency of the output would be 10 Hz. You can change the amplitude of the output by changing the default gain of 9.95 to anything between 0 and 10.
01-11-2011 01:21 AM
Thanks but one last thing ,
can you explaine the other values in
data[i] = 9.95*sin((double)i*2.0*PI/1000.0);
9.95 is amp .
what are the others ?
01-11-2011 01:34 AM
Sorry plz ignore the last question 🙂 thanks for the help !!!
02-25-2011 01:30 AM
Dear Steven:
Could you tell us , if wan to Generating 0.1~0.001HZ Sin Wave, Then how to change the Sin Generate func.
9.95*sin((double)i*2.0*PI/1000.0); --->the example Generate 1HZ Sin Wave.
9.95 is Amp
And If want to Generate other wave(ex: Triangle wave,Sawtooth wave,Square wave) the Generate function
Thanks your kindly support!
02-28-2011 01:56 PM
Hello,
Can you provide me with the example that you are using so I can see what the options are?
Thank you,
Justin
02-28-2011 08:50 PM
Hello Justin
attach my example code, then it generate 1Hz Sin wave sample,(How to generate 0.1Hz base Sin Wave function?)
then if want to generate continuous 2.7Hz Sin wave the rule
float data[1000] = {0.0};
float fFreq = 1.0;
for(int i=0; i<nDataSample; i++)
data[i] = 1*sin((double) i*2.0*PI*fFreq/1000);
// fFreq the generate 1Hz continuous Sin wave,
// But if change to 2.7,then it couldn't generate continuous 2.7Hz Sin wave
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateAOVoltageChan(g_taskHandle,"Dev1/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(g_taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxRegisterDoneEvent(g_taskHandle,0,DoneCallback,NULL));
/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk (DAQmxWriteAnalogF64(g_taskHandle,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(g_taskHandle));
03-01-2011 01:24 AM