Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring PXIe 6363 Analog Output and Counter synchronization

Using 6363 with DAQmx C interface.

I'm trying to configure the DAQ in two different ways (let's call them A and B).  I have them both sort of working, but it's using a lot of software callbacks, starting and stopping the tasks, etc., and I'm certain this is not the right way.

 

Config A goal: Write analog output at a slow rate (2 Hz or so), and printf something to the console at each sample.  Currently I write the minimum of 2 samples at a time, one of which is a  dummy value, then in the DoneWriteCallback, I printf to the console, stop the task, write the next sample, then start the task again.  I get an error if I just try restarting the task, without stopping it first.  I'm certain I tried writing all the samples at once, along with EveryNCallback, but for some reason I couldn't get this to work (this was last year, so I don't remember what I tried).  I'm also not sure whether DoneWriteCallback gets called as soon as the data has been written to the buffer, or 500ms later at the end of the sample period.  This technique seems to work, so it appears to call DoneWriteCallback at the end of the sample period, but I couldn't find any documentation about this.

 

Config B goal: Write analog output, and for each sample, printf to console, wait a few ms, and output several pulses from counter, taking an analog input with each pulse, then go to the next analog output value; the analog input value should be available in software before the pulse is sent.  It seems I should trigger the CTR0 output with the AO start trigger, then when the CTR0 output stops, make the AO task go to the next sample.  Or I could set up the analog input to output its start trigger on the digital output as my pulse instead of a CTR0 task.  I have no idea where to start with this.  I have just modified config A to stop and start the CTR0 task with every DoneWriteCallback, along with the AO task itself, and the AI task runs completely independently.

 

Perhaps I can learn to fish instead.

 

 

Below is the abbreviated code which does everyhing:

// ANALOG INPUTS
char aiPhysNames[] = "Dev1/ai16,Dev1/ai17,Dev1/ai18";
char aiNames[] = "AUX X,AUX Y,AUX Z";

DAQmxErrChk(DAQmxCreateTask("Analog Input Task", &hAItask));
DAQmxErrChk(DAQmxCreateAIVoltageChan(hAItask, aiPhysNames, aiNames, DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, NULL));

DAQmxErrChk(DAQmxSetStartTrigDelayUnits(hAItask, DAQmx_Val_Seconds));
DAQmxErrChk(DAQmxSetStartTrigDelay(hAItask, 1e-3));
DAQmxErrChk(DAQmxCfgSampClkTiming(hAItask, "", inRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, sizeof(Triple64)));
DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(hAItask, DAQmx_Val_Acquired_Into_Buffer, 1, 0, DAQ::_everyNReadCallback, this));
DAQmxErrChk(DAQmxRegisterDoneEvent(hAItask, 0, DAQ::_doneReadCallback, this));
DAQmxErrChk(DAQmxCfgInputBuffer(hAItask, 0));
DAQmxErrChk(DAQmxCfgInputBuffer(hAItask, numSamples)); // * 3??

// ANALOG OUTPUTS
char aoPhysNames[] = "Dev1/ao3,Dev1/ao2,Dev1/ao1";
char aoNames[] = "XDRIVE,YDRIVE,ZDRIVE";
int32 aoWritten = 0;

DAQmxErrChk(DAQmxCreateTask("Analog Output Task", &hAOtask));
DAQmxErrChk(DAQmxCreateAOVoltageChan(hAOtask, aoPhysNames, aoNames, -10.0, 10.0, DAQmx_Val_Volts, NULL));
//DAQmxErrChk(DAQmxCfgSampClkTiming(hAOtask, "", outRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples));
DAQmxErrChk(DAQmxCfgSampClkTiming(hAOtask, "", outRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2));
//DAQmxErrChk(DAQmxWriteAnalogF64(hAOtask, numSamples, 0, -1, DAQmx_Val_GroupByScanNumber, (float64 *)outData, &aoWritten, NULL));
//DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(hAOtask, DAQmx_Val_Transferred_From_Buffer, 1, 0, DAQ::_everyNWriteCallback, this));
DAQmxErrChk(DAQmxCfgOutputBuffer(hAOtask, 0));
DAQmxErrChk(DAQmxCfgOutputBuffer(hAOtask, numSamples)); // * 3??
DAQmxErrChk(DAQmxRegisterDoneEvent(hAOtask, 0, DAQ::_doneWriteCallback, this));

 

// COUNTER 0 PULSE OUTPUT

DAQmxErrChk(DAQmxCreateTask("Pulse Output", &hPUtask));

DAQmxErrChk(DAQmxCreateCOPulseChanFreq(hPUtask, "Dev1/ctr0", "", DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, pulseDef.frequency, pulseDef.duty));
DAQmxErrChk(DAQmxCfgImplicitTiming(hPUtask, DAQmx_Val_FiniteSamps, pulseDef.count));

//DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(hPUtask, "Dev1/ao/StartTrigger", DAQmx_Val_Rising)); // <- didn't work

 

// START EVERYTHING

DAQmxErrChk(DAQmxStartTask(hAItask));

wprintf(L"Setting initial field value %d to %f, %f, %f\n", outputIndex, out.x, out.y, out.z);
DAQmxErrChk(DAQmxWriteAnalogF64(hAOtask, 2, 0, -1, DAQmx_Val_GroupByScanNumber, (float64 *)outData, &aoWritten, NULL));
DAQmxErrChk(DAQmxStartTask(hAOtask));
DAQmxErrChk(DAQmxStartTask(hPUtask));

 

int32 CVICALLBACK DAQ::_doneWriteCallback(TaskHandle taskHandle, int32 status, void *callbackData) {

    // Other stuff to choose next sample

    wprintf(L"Setting new field value %d to %f, %f, %f\n", pThis->outputIndex, out->x, out->y, out->z);
    DAQmxErrChk(DAQmxStopTask(taskHandle));
    DAQmxErrChk(DAQmxStopTask(pThis->hPUtask));
    DAQmxErrChk(DAQmxWriteAnalogF64(taskHandle, 2, 0, -1, DAQmx_Val_GroupByScanNumber, (float64 *)out, &aoWritten, NULL));
    DAQmxErrChk(DAQmxStartTask(taskHandle));
    DAQmxErrChk(DAQmxStartTask(pThis->hPUtask));

}

 

int32 CVICALLBACK DAQ::_everyNReadCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) {

    DAQmxErrChk(DAQmxIsTaskDone(pThis->hAOtask, &done));
    DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, nSamples, 10.0, DAQmx_Val_GroupByScanNumber, (float64 *) &pThis->inData, 3, &readAI, NULL));

    // Other stuff to make data available elsewhere

}

 

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

Hello RedmondUser

 

Did you get an error code or something similar?

 

Also, in this case we need to narrow down the issue so, is there possible to use each task separately like analog input, output? Just to check.

 

Feel free to use the example codes

 

Regards

0 Kudos
Message 2 of 3
(2,991 Views)

I'll dig into this more deeply later this week and post narrow, specific questions if they come up.

0 Kudos
Message 3 of 3
(2,988 Views)