LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating Sin Wave with NI-6733

Solved!
Go to solution

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.....

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 1 of 8
(4,576 Views)
Solution
Accepted by topic author Kobi_K

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.  


Steven K.
National Instruments
Software Engineer
0 Kudos
Message 2 of 8
(4,552 Views)

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 ?

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 3 of 8
(4,530 Views)

Sorry plz ignore the last question 🙂 thanks for the help !!!

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 4 of 8
(4,526 Views)

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!

0 Kudos
Message 5 of 8
(4,403 Views)

Hello,

 

Can you provide me with the example that you are using so I can see what the options are?

 

Thank you,

 

Justin

Justin
National Instruments
Product Support Engineer - Conditioned Measurements
Message 6 of 8
(4,377 Views)

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));

0 Kudos
Message 7 of 8
(4,366 Views)

Hi,

 

here is some information about sine waves,

 

hth, Wolfgang

0 Kudos
Message 8 of 8
(4,356 Views)