Hi All,
Environment: NI-DAQmx, ANSI C-API, PCI-6229 card
I'm trying to do continuous AIN voltage readings while doing buffered edge counting on CTR0, and I'm trying to synchronize the counter readings with my AIN readings, but so far am not having much luck. I thought that since CTR0 requires an external clock for it's gate, I could route the "/Dev1/ai/SampleClock" signal to RTSI0, and then use RTSI0 as the gate for counter 0. So far, I'm not having any success. I can read many samples from the AIN task, but I always get 0 samples from the CTR task (acting as if the counter is not being gated).
What am I doing wrong here? I've attached a simple console test app below...
Thanks in advance for any help!
-bill
// console_6229.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "NIDAQmx.h"
#include "conio.h"
#include "iostream"
using namespace std;
void ErrText(int err, char *s, int siz){
if (err==0) return;
DAQmxGetExtendedErrorInfo (s,siz);
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
TaskHandle h_AIN=0;
TaskHandle h_CTR=0;
int err;
char s[512];
int16 readArray1[10000];
uInt32 ctrArray_0[10000];
int32 sampsPerChanRead1=0;
int32 ctrPerChanRead_0=0;
err=DAQmxResetDevice("Dev1");
ErrText(err,s,sizeof(s));
err=DAQmxGetDevProductType("Dev1",&s[0],511); // const char device[], char *data, uInt32 bufferSize);
ErrText(err,s,sizeof(s));
cout << "Device type = " << s << endl;
err=DAQmxCreateTask("",&h_AIN); // create a task for the AINS
err=DAQmxCreateTask("",&h_CTR); // create a task for counter 0
__try
{
err=DAQmxCreateAIVoltageChan(h_AIN,"Dev1/ai0","",DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NULL);
ErrText(err,s,sizeof(s));
err=DAQmxCfgSampClkTiming (h_AIN, "",1000,DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000);
ErrText(err,s,sizeof(s));
// setup the counters to do buffered edge counting
err=DAQmxCreateCICountEdgesChan (h_CTR,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp);
ErrText(err,s,sizeof(s));
err=DAQmxExportSignal (h_AIN, DAQmx_Val_SampleClock,"RTSI0");
ErrText(err,s,sizeof(s));
err=DAQmxCfgSampClkTiming (h_CTR, "RTSI0",1000,DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000);
ErrText(err,s,sizeof(s));
// indicate that we will start the tasks in software (as opposed to a hardware trigger)
err=DAQmxDisableStartTrig(h_AIN);
ErrText(err,s,sizeof(s));
// start the slave tasks first (this "arms" the counter tasks)
err= DAQmxStartTask(h_CTR);
ErrText(err,s,sizeof(s));
// finally start the master tasks
err= DAQmxStartTask(h_AIN);
ErrText(err,s,sizeof(s));
while( !_kbhit() )
{
err=DAQmxReadBinaryI16(h_AIN, -1, 0,DAQmx_Val_GroupByScanNumber,&readArray1[0], 1000, &sampsPerChanRead1, NULL);
if((err) && (err!= -200284)) {
ErrText(err,s,sizeof(s));
}
err=DAQmxReadCounterU32(h_CTR,-1,0.0,&ctrArray_0[0],1000,&ctrPerChanRead_0,NULL);
ErrText(err,s,sizeof(s));
cout << "counter samples read=" << ctrPerChanRead_0;
cout << " AIN samples read=" << sampsPerChanRead1 << " \r";
Sleep(100);
}
_getch();
cout << endl;
cout << "finished - press a key..." << endl;
while( !_kbhit() ) {}
_getch();
}
__finally
{
DAQmxClearTask(h_AIN);
DAQmxClearTask(h_CTR);
}
return 0;
}