Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set an external AO reference after a single point analog output ?

Hello,
I am experiencing a strange problem when programming a PCI-6259 by LabWindows/CVI (the example "External_AO_Reference.zip" available on the NI website was used).
I am trying to output a waveform from AO0 after having previously set AO0 itself to a single fixed value by means of a dedicated task (by the way, the idea is then to slowly move the dac output from the actual value to a value matching exactly the first point of the future waveform, thus avoiding abrupt changes at the output).
Only after the dac AO0 is set to a value (say -3V) I stop and clear the respective task and create the waveform generation one using an external reference. As soon as I write the buffer into the DAC, the output suddenly changes to an unexpected value(say -0.59V), thus voiding the previous single point setting. Then the waveform generation occurs in the expected output range.

This is the code used to set AO0 to a single fixed value:

int32 CreateAO_VWriteTask(TaskHandle *taskOut1, char *line, char *mnemonic, float64 minVal, float64 maxVal)
{
    TaskHandle taskOut;

    DAQmxCreateTask("AO_VWriteTask", &taskOut);

    DAQmxCreateAOVoltageChan(taskOut, line, mnemonic, minVal, maxVal, DAQmx_Val_Volts, "");
    if (-1 != DAQmx_Val_Cfg_Default)
        DAQmxSetChanAttribute(taskOut, mnemonic, DAQmx_AO_TermCfg, -1);

    *taskOut1 = taskOut;
   
    return 0;
}

void SetDac0To(double offsetx)  
{
    char dpl[40]; 
    TaskHandle FastScanDacTask = 0; 
   
    Fmt(dpl, "%s<%s%d%s%d", "Dev", 1, "/ao", 0);
    CreateAO_VWriteTask(&FastScanDacTask, dpl, "FastScanDac", -10.0, 10.0);
   
    DAQmxWriteAnalogScalarF64 (FastScanDacTask, 1, 10.0, offsetx, 0); 
   
    if (FastScanDacTask != 0)     { DAQmxStopTask(FastScanDacTask); DAQmxClearTask(FastScanDacTask); } 
}

And, referring to the mentioned example, here is the code showing the problem:

       
        SetDac0To (-3.0);                                                                                                                     // added to preset AO0 out

        DAQmxErrChk (Configure_ContGenPerWfmIntClk(chan,min,max,rate,&taskHandle));
       
        GetCtrlVal (panelHandle, PANEL_REF_VALUE, &refValue);
       
        // Specify and external reference, which connector pin to input it, and the value it will be.
        DAQmxSetChanAttribute (taskHandle, chan, DAQmx_AO_DAC_Ref_Src, DAQmx_Val_External);
        DAQmxSetChanAttribute (taskHandle, chan, DAQmx_AO_DAC_Ref_ExtSrc, "/Dev4/APFI0");
        DAQmxSetChanAttribute (taskHandle, chan, DAQmx_AO_DAC_Ref_Val, refValue);
                                                                                                                                                      // until here AO0 out = -3V
        DAQmxErrChk (Write_ContGenPerWfmIntClk(taskHandle,data,sampsPerCycle));                        // here I observe the sudden AO change to about  -0.59 V                                                                                  
        DAQmxErrChk (Start_ContGenPerWfmIntClk(taskHandle));                                                         // here the waveform is output on AO0 as expected


I have tried many settings and obtained the same behaviour.
Presetting the dac output is of major importance in my application where any sudden change must be avoided.
Can anybody suggest a fix to this problem ?

Thanks in advance,
Marco


0 Kudos
Message 1 of 1
(3,036 Views)