Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

sampling rate, time stamp

Solved!
Go to solution

See below.

Message Edited by kgy on 04-02-2009 04:00 PM
0 Kudos
Message 1 of 12
(5,249 Views)

 Sorry, the previous post is messed up.

 

I'm using DAQmx USB6289 to collect data from 15 channels. sampling rate is 1khz. I use DAQmxRegisterEveryNSamplesEvent to continuously collect data. I have some questions regarding attaching time stamp to the data points.

 

 

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
 {
                DAQmxGetReadRelativeTo(taskHandle, position);
 DAQmxSetReadRelativeTo(taskHandle,position[0]-50+1);// to get the most recent 50 data scan or sample?
DWORD currenttime = GetTickCount();/ /get the current time, which will be in the unit of ms.
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,g_nsample,10.0,DAQmx_Val_GroupByScanNumber,data,50*15,&read,NULL));
  }

 

My questions are
1) for "DAQmxSetReadRelativeTo(taskHandle,position[0]-50+1);", will it point to the most recent 50 scan of data samples (50*15channels) or just most recent 50 data samples?
2) how to associate time stamps to the data? for example, I use " currenttime = GetTickCount();/ " right before 'DAQmxReadAnalogF64', can I directly use interval of 1ms to the collected data or scan?
for example, if the answer for question 1 is 'scan', then
                    DATA                         time stamp
data[1,1],data[1,2],....data[1,15]  currentime-50+1
data[2,1],data[2,2],....data[2,15] currentime-50+2
....
data[50,1],data50,2],....data[50,15]  currenttime

 

if the answer for question 1 is 'data sample', then
data[1,1],      data[1,2],....   data[1,15]
currentime-49 ...............................
data[2,1],       data[2,2],....  data[2,15]
(...                                    currentime-5)
data[3,1],       data[3,2],.    data[3,5] 
(currentime-4 currentime-3 currentime)

 

Am I correct?

 

This is the setting the DAQ connection:

void DataCollectionWin::ConnectDAQ() //for the connection part
{
             DAQmxErrChk(DAQmxCreateTask ("", &taskHandle));
            DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3,Dev1/ai4,Dev1/ai5,Dev1/ai16,Dev1/ai17,Dev1/ai18,Dev1/ai19,Dev1/ai20,Dev1/ai21,Dev1/ai6,Dev1/ai7,Dev1/ai22","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
  DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,60000));
  DAQmxSetReadOverWrite(taskHandle,DAQmx_Val_OverwriteUnreadSamps);
  DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,g_nsample,0,EveryNCallback,NULL));
  DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
  DAQmxErrChk (DAQmxStartTask(taskHandle));
}

Message Edited by kgy on 04-02-2009 03:59 PM
0 Kudos
Message 2 of 12
(5,247 Views)

It should read 50 samples for each channel.

 

If you read the data in as a waveform it will already have a timestamp associated with it.

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 3 of 12
(5,224 Views)

Thank you for the reply. What do you mean read the data as a waveform? How to get the time stamp?

I collected some data and check the time intervals tween each group of data (50*15). Then I found the time intervals sometime below 50ms! I won't be suprised if it is larger than 50ms because the program is also taking time to save the data into a file after collection. But less than 50ms?? Does it mean the sample rate is faster than 1KHz? How's that happen?

 

0 Kudos
Message 4 of 12
(5,222 Views)

How to read data as waveform using vc++? I can't find the function in the help file.

 

Thank you.

0 Kudos
Message 5 of 12
(5,213 Views)
Anyone can help me on it pls? Thank you.
0 Kudos
Message 6 of 12
(5,190 Views)
I would recommend you take a look at some of the example programs found in Start»Programs»National Instruments»NI-DAQ»Text-Based Code Support or on the community, and go from there.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 7 of 12
(5,181 Views)
I have been struggling for quite some time. All the examples I found in the forum using waveform are labview examples or seemingly using measurement studio functions (I don't have measurement studio). I really got no clue how to read waveform using vc++ or attaching time stamp acurately to the data samples using VC++. I would appreciate a lot if someone can help me out. Thank you.
0 Kudos
Message 8 of 12
(5,176 Views)
I apologize, there is actually no way to read a waveform in ANSI C.  My recommendation would be then to read the system time from the computer immediately before the start of your data acquisition process.  This will be just as accurate as using the waveform method, as that is essentially what the waveform does.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 9 of 12
(5,164 Views)

Thank you, Doug. If I use DAQmxReadAnalogF64 to read out all the available data in the buffer, should the system time be associated to the first data or the last data in the buffer?

 

For example, if I put following setting (sample rate:1kz)

 

DWORD currenttime = GetTickCount();/ /get the current time, which will be in the unit of ms.
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,-1,10.0,DAQmx_Val_GroupByScanNumber,data,60000*15,&read,NULL));

 

then

1) data[1]: current time; data [2]: current time+1ms;....data [n]: current time+n-1ms or

 

2) data[read]: current time; data[read-1]:current time -1ms; data[read-n]: current time-n+1ms

 

Which one is correct? I previously set to read 50 most recent data samples (see above). But it seems there are overlaps between the groups (50 samples each group). It shows sometimes the intervals between two groups are less than 50 ms, which is expected to be the minimum interval for reading 50 samples since the sampling rate is 1kz. Also I read some previous posts regarding the time difference between the actual hardware aquiring the data and the software reading the data. How to get round of this issue?

 

In addition, if I read out all the available data, how to set "arraySizeInSamps"? Should I just use a array size as large as possible? Thank you.

Message Edited by kgy on 04-06-2009 05:27 PM
Message Edited by kgy on 04-06-2009 05:29 PM
0 Kudos
Message 10 of 12
(5,161 Views)