Hi there!
I'm trying to program a M-6221 card. Because i want to have some more analog inputs, i'm trying to install a 8:1 analog multiplexer (MPC508).
At first i thought, my hardware wasn't good enough. I wasn't able to scan my channels faster than 1kHz. I had the problem, that the multiplexer did not switch fast enough between the channels (or didn't switch at all).
But when i disabled my software setting of the sampleclock, suddenly all worked well. Am i a bit stupid at the moment? Or can anyone explan this phenomen to me? I'm writing in VC++.
As soon as i enable the line with configuring the sampleclock, the multiplexer switches badly and my measuring results are bad.
The writeIntToBinaryArray just writes number in binary array form.
int writeIntToBinaryArray(uInt8 array[], int lengthofarray, int number, bool beginwithindexzero)
Here is a code excerpt:
[quote]
//create the task
DAQmxCreateTask("InputTask", &InputHandle);
DAQmxCreateTask("OutputTask", &OutputHandle);
//create the AI channel
for (i=0;i<channelcount;i++)
{
devicename.Format("/dev1/ai%i", 0*i);
DAQmxCreateAIVoltageChan(InputHandle, devicename, "", DAQmx_Val_RSE, -10.0, 10.0, DAQmx_Val_Volts, NULL);
}
DAQmxCreateDOChan(OutputHandle, "dev1/port0/line0:2", "", DAQmx_Val_ChanForAllLines);
//configure sampleclock
//DAQmxCfgSampClkTiming(InputHandle, "", samplerate, DAQmx_Val_Rising, DAQmx_Val_HWTimedSinglePoint, buffersize);
//DAQmxCfgSampClkTiming(OutputHandle, "", samplerate, DAQmx_Val_Rising, DAQmx_Val_HWTimedSinglePoint, buffersize);
DAQmxStartTask(InputHandle);
DAQmxStartTask(OutputHandle);
while(!_kbhit())
{
writeIntToBinaryArray(digitalarray, 3, multiplexin, true);
DAQmxWriteDigitalLines (OutputHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, digitalarray, &digsampswritten, NULL);
while (digsampswritten<1);
DAQmxReadAnalogF64(InputHandle, sampstoread, -1, DAQmx_Val_GroupByChannel, analoginputdata, buffersize, &samplecounter, NULL);
while (samplecounter<sampstoread);
.
.
//do something
}