Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Input Problems

hello
I can't find in NI-DAQ™mx C Reference Help any information how use double-buffered DAQ operations.
I would like to set 128 times signal from -10V to +10V with resolution=0,3mV for Analog Output channel and
I would like to measure 128 times signal from -10V to +10V with resolution=156mV in Analog Imput channel.
Data from Analog Imput chanel shold be set in BUFOR each times (1,2,3...128)
How I can do this using function from NI-DAQ™mx C Reference Help ??? for M Series NI PCI 6259 CARD


I wrote this but it doesn't work?
X=128;
pTabDataAO = new double[65536];
pTabDataAI = new double[X*X];


//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO//AO
DAQmxCreateTask ("",&RampaAoTaskHandle);
DAQmxCreateAOVoltageChan(RampaAoTaskHandle,"Dev1/ao0","",-10.0f,10.0f,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(RampaAoTaskHandle,"OnboardClock",float(pow(2,16)),DAQmx_Val_Falling,DAQmx_Val_ContSamps,65536);
int32 written;
DAQmxWriteAnalogF64(RampaAoTaskHandle,65536,0,-1,DAQmx_Val_GroupByScanNumber,pTabDataAO,&written,NULL);

//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai//Ai
DAQmxCreateTask ("",&RampaAiTaskHandle);
DAQmxCreateAIVoltageChan(RampaAiTaskHandle,"Dev1/ai0","",DAQmx_Val_RSE,-10.0f,10.0f,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(RampaAiTaskHandle,"OnboardClock",float(pow(2,7)),DAQmx_Val_Falling,DAQmx_Val_ContSamps,X);

DAQmxStartTask(RampaAoTaskHandle);
DAQmxStartTask(RampaAiTaskHandle);
DAQmxCfgDigEdgeStartTrig(RampaAoTaskHandle,"ai/StartTrigger",DAQmx_Val_Falling);
DAQmxReadAnalogF64(RampaAiTaskHandle,X,-1.0,DAQmx_Val_GroupByScanNumber,pTabDataAI,X,&ifread,NULL);
0 Kudos
Message 1 of 9
(3,521 Views)
I haven't gotten as far as trying to do two things at once with DAQmx, but I see a couple of things I would do differently.

First, you aren't checking the error return of any of your calls to DAQmx. You really need to do this, or you don't know if something is failing. I think it is likely that some call is failing.

I would order the calls differently. You are presently doing this:

Create AO task
Create AO channel
Write AO
...
Start AO


Perhaps it would be better to do this:

Create AO task
Create AO channel
Cnf AO Timing
Create AI task
Create AI channel
Cnf AI Timing
Start AO
Start AI
Write AO
Read AI

As I say, I haven't actually tried it 🙂
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 2 of 9
(3,501 Views)
Thanks for yor suggestion
I try it, but I try so far a lot of combination and any doesn't work
I don't know whay there is so hard to measure singals by using PCI card create for it!!!
Best Regards
0 Kudos
Message 3 of 9
(3,492 Views)
One thing that I see which is probably causing you problems (I would take John's suggestion and check for errors ) is that you are configuring your start trigger after you have started the tasks. That won't work and should return an error. You need to do all of your configuration before starting the tasks.

StuartG
0 Kudos
Message 4 of 9
(3,471 Views)
Hello
1. This code is from NI examples delivered with the PCI Card
2. Everything goes well but I measuer signal from AI channel only once, despite I set "DAQmx_Val_ContSamps"
DAQmxCfgSampClkTiming(RampaAiTaskHandle,"OnboardClock",float(pow2,7)),DAQmx_Val_Falling,DAQmx_Val_ContSamps,X);
But I would like to measuer AI chanel 128 times;
Whay this functions
DAQmxCfgSampClkTiming(RampaAiTaskHandle,"OnboardClock",float(pow2,7)),DAQmx_Val_Falling,DAQmx_Val_ContSamps,X);
works like this one
DAQmxCfgSampClkTiming(RampaAiTaskHandle,"OnboardClock",floatpow2,power)),DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,X);
wchich means that DAQmx_Val_ContSamps=DAQmx_Val_FiniteSamps
This is my problem
Best Regards
0 Kudos
Message 5 of 9
(3,462 Views)
Hi,

Which example are you using? I can run it and see if I get the same behavior.

George
0 Kudos
Message 6 of 9
(3,440 Views)
Hello
I usein NI PCI 6259 M Series Card
This program I wrote by my self. The proble is that I would like to measure signal from Analog Input channel a couple of times without PCI CPU, without Start Analog Input Task evwery times when I want to fill the buffer. So the bufer should be big. I think that mayby is posible send signal from Analog Input chanell by use DMA to PCI memeory?

int power;
int X=128;
pTab2DDane = new double[X*X];
pTabDataAO = new double[65536];
pTabDataAI = new double[X*X];


//Ai
DAQmxCreateTask ("",&RampaAiTaskHandle);
DAQmxCreateAIVoltageChan(RampaAiTaskHandle,chanAI,"",DAQmx_Val_RSE,-10.0f,10.0f,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(RampaAiTaskHandle,"OnboardClock",float(pow(2,7)),DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,X);
//AO
DAQmxCreateTask ("",&RampaAoTaskHandle);
DAQmxCreateAOVoltageChan(RampaAoTaskHandle,chanAO,"",-10.0f,10.0f,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(RampaAoTaskHandle,"OnboardClock",float(pow(2,16)),DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,65536);
int32 written;
DAQmxWriteAnalogF64(RampaAoTaskHandle,65536,1,-1.0,DAQmx_Val_GroupByScanNumber,pTabDataAO,&written,NULL);

DAQmxCfgDigEdgeStartTrig (RampaAoTaskHandle,"ai/StartTrigger",DAQmx_Val_Falling );

DAQmxStartTask(RampaAoTaskHandle);
DAQmxStartTask(RampaAiTaskHandle);

ifread=0;
DAQmxReadAnalogF64(RampaAiTaskHandle,X,-1.0,DAQmx_Val_GroupByScanNumber,pTabDataAI,X*X,&ifread,NULL);

I would like to fill Analog Input Buffer (X*X) times but it fill (X) time and stop acquisition. Whay? Where I can set to measuuer Analog Input Signal a couple of times (X*X) without Start Analog Input Task every time.
Best Regards
0 Kudos
Message 7 of 9
(3,434 Views)
You're still not checking the return values from the DAQmx... calls. That's a fundamental mistake in programming.

This is easily understandable (but not compiled or run, so it may contain errors):

int32 error;
if (error = DAQmx...(...whatever...))
{
uInt32 nchars;
if ( (nchars = DAQmxGetErrorString(error, NULL, 0)) > 0)
{
char *msg = new char[nchars];
DAQmxGetErrorString(error, msg, nchars);
// ... do something with the message ...
cout << "Error calling DAQmxWhatEver:" << error << ": " << msg << "\n";
delete [] msg;
}
}

but it makes the program hard to read. The C DAQmx examples have macros for checking errors that make the code easy to read while also checking for errors.

This is doubly important when doing something like DAQ programming where success depends on the hardware. Even correctly-written code can fail if the hardware fails, or if the rates are exceded, or any of a number of failures occurs that you can't anticipate.

I wrote a special error-printing class as one of the very first things I did when I started programming DAQmx. I learned some surprising things!
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 8 of 9
(3,416 Views)
Hello
Thanks that you are answering for my question 🙂
I correct my programs to receive PCI card message.
Best Regards
0 Kudos
Message 9 of 9
(3,412 Views)