01-03-2012 06:49 PM
I want to use counter pulse which uses external source into PFI8 for analog input/output. I am using PCI-6111 and DAQmx 9.4.
With Traditional DAQ 7.4.4, the following code could what I want.
iStatus = Select_Signal (m_deviceNumber, ND_RTSI_0, ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH); iStatus = Select_Signal (m_deviceNumber, ND_IN_SCAN_START, ND_RTSI_0, ND_LOW_TO_HIGH); iStatus = GPCTR_Control(m_deviceNumber, ND_COUNTER_0, ND_RESET); iStatus = GPCTR_Set_Application (m_deviceNumber, ND_COUNTER_0, ND_PULSE_TRAIN_GNR); iStatus = GPCTR_Change_Parameter (m_deviceNumber, ND_COUNTER_0, ND_SOURCE, ND_PFI_8); iStatus = GPCTR_Change_Parameter(m_deviceNumber, ND_COUNTER_0, ND_COUNT_1, ulLOWcount); iStatus = GPCTR_Change_Parameter(m_deviceNumber, ND_COUNTER_0, ND_COUNT_2, ulHIGHcount); iStatus = GPCTR_Control(m_deviceNumber, ND_COUNTER_0, ND_PREPARE); iStatus = Timeout_Config (m_deviceNumber, timeout); iStatus = WFM_Group_Control (m_deviceNumber, 1, 0); iStatus = AO_VWrite (m_deviceNumber, ANALOG_OUTPUT_CHAN, 0.0); iStatus = Select_Signal (m_deviceNumber, ND_OUT_UPDATE, ND_RTSI_0, ND_LOW_TO_HIGH); iStatus = WFM_Load (m_deviceNumber, 1, chanVect, dataArray, iNumPoints, 1, 0); iStatus = WFM_ClockRate (m_deviceNumber, 1, 0, 0, 1, 1); iStatus = WFM_Group_Control (m_deviceNumber, 1, 1); iStatus = DAQ_Start (m_deviceNumber, ANALOG_INPUT_CHAN, range, collectionBuffer, iNumDataPoints, 0, 1); iStatus = GPCTR_Control(m_deviceNumber, ND_COUNTER_0, ND_ARM); iStatus = DAQ_Check (m_deviceNumber, &daqStopped, &retrieved); while (daqStopped !=1 && iStatus ==0) { iStatus = DAQ_Check (m_deviceNumber, &daqStopped, &retrieved); Sleep(100); } iStatus = GPCTR_Control(m_deviceNumber, ND_COUNTER_0, ND_DISARM); iStatus = DAQ_VScale (m_deviceNumber, ANALOG_INPUT_CHAN, range, externalGain, 0, iNumDataPoints, collectionBuffer, voltArray); //Start another buffer data collection if needed iStatus = DAQ_Clear (m_deviceNumber);
With DAQmx, I changed the code as follows:
iStatus = DAQmxConnectTerms("/Dev1/Ctr0InternalOutput", "/Dev1/RTSI0", DAQmx_Val_DoNotInvertPolarity); iStatus = DAQmxCreateTask("", &inTaskHandle); iStatus = DAQmxCreateTask("", &outTaskHandle); iStatus = DAQmxCreateTask("", &counterTaskHandle); iStatus = DAQmxCreateCOPulseChanTicks( counterTaskHandle, "Dev1/ctr0", "", "/Dev1/PFI8", DAQmx_Val_Low, 0, iLOWcount, iHIGHcount); iStatus = DAQmxCreateAOVoltageChan( inTaskHandle, "/Dev1/ao0", "", -10.0, 10.0, DAQmx_Val_Volts, NULL); // write initial value of 0 to the output so we have the same starting state iStatus = DAQmxWriteAnalogScalarF64( outTaskHandle, false, timeout, 0.0, NULL ); iStatus = DAQmxCfgSampClkTiming( outTaskHandle, "/Dev1/RTSI0", 1, /* arbitrary with external clock */ DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000 /* automatically determined by sample interval */ ); iStatus = DAQmxWriteBinaryI16( outTaskHandle, iNumPoints, true, /* Start automatically */ timeout, DAQmx_Val_GroupByChannel, dataArray, NULL, NULL); iStatus = DAQmxCreateAIVoltageChan( inTaskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, - cdRangeMaximums[range], cdRangeMaximums[range], DAQmx_Val_Volts, NULL); iStatus = DAQmxCfgSampClkTiming( inTaskHandle, // task handle "/Dev1/RTSI0", // clock source 1.0, // sampling frequency (ignored for external clock) DAQmx_Val_Rising, // sampling timing DAQmx_Val_FiniteSamps, // finite samples iNumDataPoints); // number of samples iStatus = DAQmxStartTask(inTaskHandle); // Start Clock iStatus = DAQmxStartTask(counterTaskHandle); iStatus = DAQmxReadBinaryI16( inTaskHandle, // task handle iNumDataPoints, // number of samples timeout, // timeout true, // Fill Mode buffer1, // output buffer iNumDataPoints, // array size &actualDataPoints, // actual data points NULL // reserved in future );
I am expecting RTSI0 is connected to counter pulse output and it is used for sampling. However, DAQmxWriteBinaryI16 and DAQmxReadBinaryI16 don't work with timeout error (-200284).
It seems that RTSI0 does not any clock pulses. Does anyone let me know what I am wrong?
Thanks,
Neppie