Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI 6002 Data Acquisition with two channels at the same time

Hello Everyone,

I have a question is it possible to read analog and counter channel at the same time with two different time loops in NI USB 6002. I am having problem that when analog signal is reading I am not able to read the counter values and when reading of analog channel is finished it starts reading counter values but then i loose some counter values.

Please help me in this

 

Thanks

0 Kudos
Message 1 of 4
(2,756 Views)

I believe you should be able to do what you describe, you just need to have separate tasks for each. Maybe you should post your code so we can see what exactly you're doing.

0 Kudos
Message 2 of 4
(2,721 Views)

 Yes,I am initializing two seperate tasks for counter and Analog channel. Below is my code logic

 

// Call Initialize channel functions

void manualMode::initializeChannels()
{
const char* waterCounter= "Dev1/ctr0";
const char* linecounter= "/Dev1/PFI0";
ni6002.intinalizeCounter(waterCounter, linecounter, samplesPerSecond);

const char* pressurechan="Dev1/ai0:2";
ni6002.intitializeReadAnalogPressure(const char* chan);

}

// Start Time Loop

void manualMode:: startTimeloop()
{
startCounterDataAcquisition =new QTimer();
connect(startCounterDataAcquisition, SIGNAL(timeout()), this, SLOT(getCounterData()));
startCounterDataAcquisition->start(100);
startAnalogDataAcquisition =new QTimer();
connect(startAnalogDataAcquisition, SIGNAL(timeout()), this, SLOT(getAnalogData()));
startAnalogDataAcquisition->start(100);
}


//"getCounterData" and "getAnalogData" function(Time Loop Functions) will be called every 100ms in a time loop

void manualMode::getCounterData()
{
readCounterData=ni6002.readCounter();
memmove(counterBuffer, readCounterData, sizeof(double)*(samplesPerSecond/10));
counterBuffer+=(samplesPerSecond/10);

readAnalogData=ni6002.readAnalogPressure();
memmove(dataBuffer, readAnalogData, sizeof(double)*3*(samplesPerSecond/10));
dataBuffer+=3*(samplesPerSecond/10);

}
void manualMode::getAnalogData()
{

readAnalogData=ni6002.readAnalogPressure();
memmove(dataBuffer, readAnalogData, sizeof(double)*3*(samplesPerSecond/10));
dataBuffer+=3*(samplesPerSecond/10);

}


TaskHandle taskHandlePressure = 0;
TaskHandle taskHandle1 = 0;

// Initialize Counter
void NI6002Communication::intinalizeCounter(const char* counter, const char* linecounter,
int samplesPerSecond)
{
DAQmxCreateTask("counter", &taskHandle1);
DAQmxCreateCICountEdgesChan(taskHandle1,counter,"",DAQmx_Val_Rising,0,DAQmx_Val_CountUp);
DAQmxCfgSampClkTiming(taskHandle1,"",0.1*samplesPerSecond,DAQmx_Val_Rising,DAQmx_Val_ContSamps,
0.1*samplesPerSecond);//sampTerm
DAQmxStartTask(taskHandle1);
}

// Initialize Analog
void NI6002Communication::intitializeReadAnalogPressure(const char* chan)
{
int samplesPerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
DAQmxCreateTask("pressure", &taskHandlePressure);
DAQmxCreateAIVoltageChan(taskHandlePressure,chan,"",DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(taskHandlePressure,"",0.1*samplesPerSecond,DAQmx_Val_Rising,DAQmx_Val_ContSamps,0.1*samplesPerSecond);
DAQmxStartTask(taskHandlePressure);
}

// Read Analog

double* NI6002Communication::readAnalogPressure()
{
int samplePerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
int32 samplesReceivedPressure = 0;
DAQmxReadAnalogF64(taskHandlePressure, 0.1*samplePerSecond, 10.0, DAQmx_Val_GroupByChannel,
dataPressure, 3*0.1*samplePerSecond, &samplesReceivedPressure, NULL);
return dataPressure;
}

// Read Counter

double *NI6002Communication::readCounter()
{
int samplePerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
int32 samplesReceivedcounterdata = 0;
DAQmxReadCounterF64(taskHandle1, 0.1*samplePerSecond,10.0, counterdata,0.1*samplePerSecond,
&samplesReceivedcounterdata,NULL);

return counterdata;
}

0 Kudos
Message 3 of 4
(2,709 Views)

Yes,I am initializing two seperate tasks for counter and Analog channel. Below is my code logic

 

// Call Initialize channel functions

void manualMode::initializeChannels()
{
const char* waterCounter= "Dev1/ctr0";
const char* linecounter= "/Dev1/PFI0";
ni6002.intinalizeCounter(waterCounter, linecounter, samplesPerSecond);

const char* pressurechan="Dev1/ai0:2";
ni6002.intitializeReadAnalogPressure(const char* chan);

}

// Start Time Loop

void manualMode:: startTimeloop()
{
startCounterDataAcquisition =new QTimer();
connect(startCounterDataAcquisition, SIGNAL(timeout()), this, SLOT(getCounterData()));
startCounterDataAcquisition->start(100);
startAnalogDataAcquisition =new QTimer();
connect(startAnalogDataAcquisition, SIGNAL(timeout()), this, SLOT(getAnalogData()));
startAnalogDataAcquisition->start(100);
}


//"getCounterData" and "getAnalogData" function(Time Loop Functions) will be called every 100ms in a time loop

void manualMode::getCounterData()
{
readCounterData=ni6002.readCounter();
memmove(counterBuffer, readCounterData, sizeof(double)*(samplesPerSecond/10));
counterBuffer+=(samplesPerSecond/10);
}
void manualMode::getAnalogData()
{

readAnalogData=ni6002.readAnalogPressure();
memmove(dataBuffer, readAnalogData, sizeof(double)*3*(samplesPerSecond/10));
dataBuffer+=3*(samplesPerSecond/10);

}


TaskHandle taskHandlePressure = 0;
TaskHandle taskHandle1 = 0;

// Initialize Counter
void NI6002Communication::intinalizeCounter(const char* counter, const char* linecounter,
int samplesPerSecond)
{
DAQmxCreateTask("counter", &taskHandle1);
DAQmxCreateCICountEdgesChan(taskHandle1,counter,"",DAQmx_Val_Rising,0,DAQmx_Val_CountUp);
DAQmxCfgSampClkTiming(taskHandle1,"",0.1*samplesPerSecond,DAQmx_Val_Rising,DAQmx_Val_ContSamps,
0.1*samplesPerSecond);//sampTerm
DAQmxStartTask(taskHandle1);
}

// Initialize Analog
void NI6002Communication::intitializeReadAnalogPressure(const char* chan)
{
int samplesPerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
DAQmxCreateTask("pressure", &taskHandlePressure);
DAQmxCreateAIVoltageChan(taskHandlePressure,chan,"",DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(taskHandlePressure,"",0.1*samplesPerSecond,DAQmx_Val_Rising,DAQmx_Val_ContSamps,0.1*samplesPerSecond);
DAQmxStartTask(taskHandlePressure);
}

// Read Analog

double* NI6002Communication::readAnalogPressure()
{
int samplePerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
int32 samplesReceivedPressure = 0;
DAQmxReadAnalogF64(taskHandlePressure, 0.1*samplePerSecond, 10.0, DAQmx_Val_GroupByChannel,
dataPressure, 3*0.1*samplePerSecond, &samplesReceivedPressure, NULL);
return dataPressure;
}

// Read Counter

double *NI6002Communication::readCounter()
{
int samplePerSecond= directoryTab.settings->value("Prefill_Sample_Rate_Hz").toInt();
int32 samplesReceivedcounterdata = 0;
DAQmxReadCounterF64(taskHandle1, 0.1*samplePerSecond,10.0, counterdata,0.1*samplePerSecond,
&samplesReceivedcounterdata,NULL);

return counterdata;
}

0 Kudos
Message 4 of 4
(2,701 Views)