Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

multi-channel analog input with Visual C

Hi! still problems with my USB-6215 and Visual C. I tried to acquire multi-analog-input-channels, but I can't understand sample flow I got.
I'd like to acquire 2 channels (interleave mode) at 250 Hz.

After creating the task, I configured the channels with the following:

DAQmxCreateAIVoltageChan(
    taskHandle,         //    this task
    "Dev1/ai0:1",       //    channel identification and # of acquiring channels
    "",                 //    name to assign to channel, left blank
    DAQmx_Val_Diff,     //    terminal configuration
    -10.0,10.0,         //    the minimum and maximum value, in units, that you expect to measure
    DAQmx_Val_Volts,    //    units
    NULL
);


Then I configured timing:

DAQmxCfgSampClkTiming(
    taskHandle,         // this task
    NULL,               // internal clock of the device is used
    250*2,              // sampling rate in samples per second per channel
    DAQmx_Val_Rising,   // active edge.....
    DAQmx_Val_ContSamps,// sampleMode: acquiring samples continuously
    0                   // I tried this with many values, very high too, but always the same result
);

After I registered my NSamplesEvent callback. I want to get samples every 100 ms, I wrote 50 in the third parameter, that is 250 (sampling frequency) every 1/10 seconds for 2 channels.

DAQmxRegisterEveryNSamplesEvent(
    taskHandle,                     //    this task
    DAQmx_Val_Acquired_Into_Buffer, //    for input task
    50,                             //    The number of samples after which each event should occur
    0,                              //    the callback is called in a DAQmx thread
    EveryNCallback,                 //    the callback function
    NULL                            //    parameter for the callback function
);

My callback is regularly called every 1/10 seconds and it is very simple, it contains the following:

int16                        data[32000];

DAQmxReadBinaryI16(
    taskHandle,       // this task
    DAQmx_Val_Auto,   // # of samples,per channel,to read. DAQmx_Val_Auto reads all available samples
    10.0,             //    timeout, in seconds, to wait for the function to read the samples
    DAQmx_Val_GroupByScanNumber,// fillMode: group samples by scan number (interleaved)
    data,             // the array to read samples into, organized according to fillMode
    sizeof(data),     // the size of the array, in samples, into which samples are read.
    &read,            // sampsPerChanRead: tThe actual number of samples read from each channel.
    NULL
);

Each buffer is sent to a Java application, no trasmission errors occur, no DAQmx errors occur.
I attached my 2nd channel to a device which output an analog triangular wave (tested with an oscilloscope).

You can see the result in the attached image.



I can't really understand why I get this result. It looks like a jump on the signal. Linearity of the triangular wave is ok within the 1/10 second buffer, then there is a jump...
Note that data is correct within 1/10 seconds. If I change configuration to get data every 1/5 seconds, then I get a correct line lasting 200 ms!
I'm sure that there is something wrong in configuration. This is the only one solution.
What' s wrong?
Can anyone help me?

Thanks a lot!

Mauro




0 Kudos
Message 1 of 4
(3,757 Views)
Greetings Naughty Bunny,
 
Your identical post is being answered here. As Filippo mentioned, you must use a comma to delimit channels and another helpful tool is the DAQmx error checking. This helps provide useful descriptions of errors that may occur in your code, as well as give suggestions for fixes when trying to acquire from multiple channels.
 
EXAMPLE:
  DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle));
  DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
  DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,sampsPerChan));
  DAQmxErrChk (DAQmxGetTaskAttribute(gTaskHandle,DAQmx_Task_NumChans,&gNumChannels));
 
Thanks and good luck!
Jordan Randall
National Instruments Italy
Message 2 of 4
(3,722 Views)
Hi Jordan, and thank for your suggestion.
I always use macro DAQmxErrChk before calling any DAQmx function, as I read it in some example. I wrote my code without DAQmxErrChk to make it more readable.
I used the notation "Dev1/ai0:1" because programming manual writes that this is a correct sintax.
Bytheway I've already done many other tests:
I tried "Dev1/ai0,Dev1/ai1" and result is the same
I tried configuring channels 1 by 1, in this way :
    DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Diff,-10.0,10.0,DAQmx_Val_Volts,NULL);
    DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai1","",DAQmx_Val_Diff,-10.0,10.0,DAQmx_Val_Volts,NULL);
but I always get the same result...
There should be some example involving many channels, but unfortunately I couldn't find.
Now I hope to find some example with LabView, trying to understand how this work...

thank you again, see you soon on this forum

/X\au|2()
0 Kudos
Message 3 of 4
(3,702 Views)
Hi, please read my last reply
Hope this could help you in helping me 🙂

Mauro
0 Kudos
Message 4 of 4
(3,683 Views)