Hi All,
I am writing a portion of code with LabWindows CVI 8.1 and NI-DAQ 8.3.0, using a PCI-6259 multifunction card.
I have slightly adjusted a synchronized ai-ao example found on the NI website. I am using an external serial dac to provide the card a voltage reference for AO0. I can correctly set the AO0 voltage but as soon as I assign the ramp array to the simultaneous ai-ao task, the AO0 output suddenly moves to a different value.
To be more exhaustive, I attach here a code snippet showing where the problem arises. Can anybody suggest a fix ?
Thanks in advance,
Marco
// code snippet showing the improper DAC setting after executing DAQmxWriteAnalogF64() below
....
// I preset dac on AO0 to -9.51 V
SetDacTo(-9.51);
// now I want a ramp ranging from -9.51V to 9.51V
ramp_X_voltage = 9.51;
// I use a proprietary serial DAC to fix the NI-dac reference voltage externally
SetVrefDacOutput(ramp_X_voltage);
// create the simultaneous input and output task
CreateSimultaneousAIAOTasks(&AIAO_AnalogInput_Task, &AIAO_AnalogOutput_Task, AIsamplerate, 2 * rowresolution, -10.0, 10.0, -10.0, 10.0, AOsamplerate, 2 * numberoframpstep, ramp_X_voltage);
// fill the ramp buffer
Ramp (numberoframpstep, -ramp_X_voltage, ramp_X_voltage, &rampa[0]);
Ramp (numberoframpstep, ramp_X_voltage, -ramp_X_voltage, &rampa[numberoframpstep]);
// ...and assign it to the task
DAQmxWriteAnalogF64(AIAO_AnalogOutput_Task, 2 * numberoframpstep, 0, 10.0, DAQmx_Val_GroupByChannel, rampa, &written, NULL);
// Yep, here a voltmeter connected to AO0 suddenly moves from -9.51 to about -9.2 !
....
// here are the main functions invoked above:
void SetDacTo(double offsetx)
{
char dpl[40];
TaskHandle FastScanDacTask = 0;
Fmt(dpl, "%s<%s%d%s", "Dev", NIDevice, "/ao0");
CreateAO_VWriteTask(&FastScanDacTask, dpl, "FastScanDac", -10.0, 10.0);
DAQmxWriteAnalogScalarF64 (FastScanDacTask, 1, 10.0, offsetx, 0);
if (FastScanDacTask != 0) { DAQmxStopTask(FastScanDacTask); DAQmxClearTask(FastScanDacTask); }
}
int32 CreateSimultaneousAIAOTasks(TaskHandle *taskHandleIn1, TaskHandle *taskHandleOut1, float64 rateIn, uInt64 sampsPerChanIn, float64 minAIVal, float64 maxAIVal, float64 minAOVal, float64 maxAOVal, float64 rateOut, uInt64 bufferSize, float64 refValue)
{
int chanNum, i;
char dpl[40];
char dpn[40];
TaskHandle taskHandleIn;
TaskHandle taskHandleOut;
DAQmxCreateTask("",&taskHandleIn);
GetNumListItems (hMainPanel, PANEL_MAINCHANNEL, &numOfChannelsInTheTask);
for (i = 0; i < numOfChannelsInTheTask; i++)
{
GetValueFromIndex (hMainPanel, PANEL_MAINCHANNEL, i, &chanNum);
Fmt(dpl, "%s<%s%d%s%d", "Dev", NIDevice, "/ai", chanNum);
Fmt(dpn, "%s<%s%d", "AICH", chanNum);
DAQmxCreateAIVoltageChan(taskHandleIn, dpl, dpn, DAQmx_Val_Diff, minAIVal, maxAIVal, DAQmx_Val_Volts, "");
}
DAQmxCfgSampClkTiming(taskHandleIn, "", rateIn, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sampsPerChanIn);
DAQmxCreateTask("",&taskHandleOut);
Fmt(dpl, "%s<%s%d%s%d", "Dev", NIDevice, "/ao", fastScanDac);
DAQmxCreateAOVoltageChan(taskHandleOut, dpl, "", minAOVal, maxAOVal, DAQmx_Val_Volts, NULL);
Fmt(dpn, "%s<%s%d%s", "/Dev", NIDevice, "/APFI0");
// Specify and external reference, which connector pin to input it, and the value it will be.
DAQmxSetChanAttribute (taskHandleOut, dpl, DAQmx_AO_DAC_Ref_Src, DAQmx_Val_External);
DAQmxSetChanAttribute (taskHandleOut, dpl, DAQmx_AO_DAC_Ref_ExtSrc, dpn);
DAQmxSetChanAttribute (taskHandleOut, dpl, DAQmx_AO_DAC_Ref_Val, refValue);
if (niCardType == PCI6289) DAQmxSetChanAttribute (taskHandleOut, dpl, DAQmx_AO_DAC_Offset_Val, 0.0);
DAQmxCfgSampClkTiming(taskHandleOut, "", rateOut, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, bufferSize);
// The output task uses the input task's start trigger. This causes the tasks to start at
// exactly the same time in hardware.
Fmt(dpl, "%s<%s%d%s", "/Dev", NIDevice, "/ai/SampleClock");
DAQmxCfgDigEdgeStartTrig (taskHandleOut, dpl, DAQmx_Val_Rising);
*taskHandleIn1 = taskHandleIn;
*taskHandleOut1 = taskHandleOut;
return 0;
}