Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6421 Analog Output Generation with C API

I need to generate two analog output signals and quickly update these signals. If someone can help me, I would like to know if by using the C API with the USB-6421 I can configure the two analog output ports in such a way that I customize the generated voltage values of each port, like an array of different values that the DAQ has to generate.
Would be DAQmxWriteAnalogF64 the correct function?
Also, how much time does it take to update this function with a new array of values?

0 Kudos
Message 1 of 2
(223 Views)

Hi corona7887,

 

Yes, DAQmxWriteAnalogF64 would be the right choice here. You can use the code snipped below as a rough guide to achieve your desired 2 analog output channel setup.

 

TaskHandle taskHandle = 0;
DAQmxCreateTask("", &taskHandle);

// assign the Dev/ao0:1 to your created task
// for info on parameters check out NI-DAQmx reference
DAQmxCreateAOVoltageChan(taskHandle, "Dev1/ao0:1", "", -10.0, 10.0, DAQmx_Val_Volts, NULL);

// assuming you want to output 100 samples
const int numSamples = 100;

// total samples = numChannels * numSamples
float64 writeArray[numChannels * numSamples];

// initialize writeArray according to data layout (here DAQmx_Val_GroupByScanNumber)
// ...

// store number of samples written per channel
int32 written;

// configure timing parameters (e.g. sample rate)
DAQmxCfgSampClkTiming(...)

// write the samples (blocking call)
DAQmxWriteAnalogF64(taskHandle, numSamples, TRUE, 10.0, DAQmx_Val_GroupByScanNumber, writeArray, &written, NULL);

DAQmxClearTask(taskHandle);

 

Note: You can also start the measurement at specific triggers instead of immediately when calling DAQmxWriteAnalogF64() (see DAQmxCfgDigEdgeStartTrig() for that).

Regarding the time it takes to update the function

The amount of time to call DAQmxWriteAnalogF64() again, with a different set of values in writeArray, is hard to estimate. It can vary, and even be interrupted assuming you dont use a real time OS.

 

Let me know if you have more questions, especially regarding the time it takes to run DAQmxWriteAnalogF64(). I'll be glad to help.

 

Best regards

Leonard

Graduate Sales Engineer @ NI

 

 

0 Kudos
Message 2 of 2
(133 Views)