Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog read sample count at digital input

Sorry I can't find and answer to this question although it seems to be very simple and basic problem.

 

I'm recording 4 analog input signals continuously (10,000hz). Once or twice a second i would like to detect a TTL on a digital input, and record the total number of samples read on the analog input conversion at that exact time. I just want to put these numbers in a double array, they are not used to trigger anything, later readout and comparison with the streamed analog data is used to identify when events occurred in relation to the recorded analog signal. I'm doing this using the ANSI c library to make a dll that I can interface from matlab.

 

Using changedetection and event driven callbacks to change a global flag that is used to record the number of samples in the analog conversion loop clearly was wrong because this leads to enormous jitter. ( I would like at least 1ms precision)

 

So the only alternative i could think of is just to sample the digital line at the same rate as the analog input and detect the TTL using c code.

I don't see how I can easily detect a TTL on a digital input line. I 'm assuming that simply a change from 0 to 1 is a TTL event, but then i get a whole series of events from just one TTL.

 

Second I'm not sure if the samples read from the digital channel is at the same frequency as that from the analog input, so if i record the number of digital input samples at TTL onset I do not know if they correspond with the number of samples at analog input at that exact time.

 

I´m wondering if there is not some standard, simple way to do this.

 

Thanks

0 Kudos
Message 1 of 7
(3,338 Views)

I forgot to mention i'm using a NI PCI-6251 on a windows XP dual core machine.

0 Kudos
Message 2 of 7
(3,332 Views)

I assume that I can synchronize the analog and digital input in the following manner, please correct me if i am wrong;

 

//analog input
DAQmxErrChk (DAQmxCreateTask("",&AItaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(AItaskHandle, "Dev1/ai0:3", "", DAQmx_Val_Diff, -5.0,5.0, DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(AItaskHandle,"", 10000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps,1000));

//digital input
DAQmxErrChk (DAQmxCreateTask("",&DItaskHandle));
DAQmxErrChk (DAQmxCreateDIChan(DItaskHandle,"Dev1/port0/line0", "", DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgSampClkTiming(DItaskHandle,"/Dev1/ai/SampleClock", 10000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps,1000));


DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(AItaskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0, AIEveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(DItaskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0, DIEveryNCallback,NULL));

DAQmxErrChk (DAQmxStartTask(DItaskHandle));
DAQmxErrChk (DAQmxStartTask(AItaskHandle));

0 Kudos
Message 3 of 7
(3,330 Views)

Since you are only using 4 of the analog input channels, record the TTL signal on one of the unused analog channels. Then you guarantee that the sample timing is the same for the analog and digital signals.  Use a threshold detection of about 1.4 V to find the leading edge of the TTL pulse. When the previous sample is < 1.4 V AND the current sample is > 1.4 V, then your pulse has started.  The index number within the array of samples tells you how many samples have been taken up to that time.  I think that is what you were trying to record.  If you read samples in blocks, of course you need to keep track of the total number of samples from previous blocks where no TTL pulse occurred.

 

I do not know anything about C, so I cannot help with that part.

 

Lynn

0 Kudos
Message 4 of 7
(3,322 Views)

Thanks for the reply. I agree just using the extra analog channels would be the simplest thing to do. However, the device attached to the NI PCI card does not give me access to the additional analog channels. So I'll juat have to do with the digital inputs. If this is really not a good option, I will have to somehow bypass the the standard cable connection  to the NI PCI 6251 card. 

0 Kudos
Message 5 of 7
(3,313 Views)

I am not familiar with that card.  Can you force the analog and digital sampling to use the same clock? If so, that will guarantee that the sample are equally spaced, although you still need to trigger both acquistions from the same signal (and determine how many clock cycles it takes to get the acquistions started).

 

Lynn

0 Kudos
Message 6 of 7
(3,304 Views)

Actually, thats what I'm hoping will be determined by using "/Dev1/ai/SampleClock" with the Digital input sampling. I've read that starting the digital task before the analog task will insure that digital sampling will only start after analog sampling commences by using the aiSampleClock. So i'm still testing this.

 

Thanks for your reply

0 Kudos
Message 7 of 7
(3,301 Views)