From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with the trigger repetition

Hi all

I am programming an application using Visual C++ .Net
and PCI-6115 DAQ, I need to acquire 300 samples each
trigger event, I have an external trigger signal of
4 KHz, the sampling rate is 5 Ms/s, I suppose that the
DAQ spends 60 microseconds in order to acquire all
the samples, I expect that the next sequences of samples
should be acquired 190 microseconds after the last sample,
but the DAQ only acquires 16.6 milliseconds after the last
sample.

Below find the part of the c++ code that I am using

for(loop_t=0;loop_t<10;loop_t++)
{

ini=clock();printf("%f\t",(double)ini);
iStatus = DAQ_Op(iDevice, iChan, iGain, piBuffer, ulCount, dSampRate);
iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Op", iIgnoreWarning);
iStatus = DAQ_VScale(iDevice, iChan, iGain, dGainAdjust, dOffset,
ulCount, piBuffer, pdVoltBuffer);
iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale",
iIgnoreWarning);

iStatus = DAQ_Clear(iDevice);
}

My question is :

Is it possible to acquire each trigger event?

What should I do in order to acquire each 4KHz trigger event?

Thanks
R. Chiu
0 Kudos
Message 1 of 3
(2,537 Views)
Hello R. Chiu,

Eventhough I am not a text based programmer when I look at your code it appears that your problem is based on the fact that you are doing a software re-arm of the trigger in which case it is very unlikely you will ever catch every trigger, simply due to OS latencies and the overhead of the function calls. And I doubt you will ever get close to a 190us re-arm time.

If I interpret your code correctly there is one immediate thing you can change. From what I see it seems that your code loops around executing the following steps - Configure, Acquire, Clear. What you want to avoid is to go through the Configure and Clear each time. Make sure you minimize the number of calls, especially configuration calls, to the board. So first Configure, then loop on re-arm and acquire, when done clear device. However, even if you do this you are still stuck with a software based re-arm of the trigger and subject to system latencies which makes me doubt you will ever be able to reliably catch every trigger of your 4kHz reference. The easiest approach to solve the problem is to acquire both channels at 5MS/s and then do your your triggering offline via software analysis. a secondary approach is to actually implement a hardware re-arm.

Let's first look at the easy approach:
Based on the code you showed I gather you want to capture 10 trigger events, I am also assuming this is period based (on every consecutive rising edge) which means that your acquisition window based on capturing 10 triggers from a 4kHz source is 2.5ms. If this is the case acquiring two channels at 5MS/s and simultaneously means you are acquiring 10MS/s. For the time period of 2.5ms this would mean that you need to acquire a total of 25000 Samples. Since the PCI-6115 has atleast 32Msample buffers you can easly acquire this directly into on-board memory without having to worry about streaming to disk. Then all that is left is to parse the data array for your trigger channel and find your trigger points and extract the desired data from your data channel starting at the same index location as that of your trigger points.

Now let's look at the hardware re-arm approach:
Don't get your hopes up. I could be wrong but my recolection is that there is no way to do a hardware re-arm on an analog trigger. So the only solution to do a hardware re-arm is if the signal is digital (TTL). So hopefully your 4kHz trigger waveform is digital or you can make it into a digital waveform. The approach then is to use a counter timer. Let me walk through the step by step setup.
1. Configure a counter timer for buffered period measurements. This will make the counter operate such that it counts the number of pulses of a defined clock that occur between rising edges of its source.
2. Configure the same counter to use the Analog Input Clock as it's clock.
3. Configure the same counter to use you 4kHz (DIGITAL SIGNAL) as it's source.
4. Configure the Analog Input to run continuously at 5MS/s.
5. Start the Analog Input
6. Start the Counter
7. Read the counter every time it has a buffer value. This value will represent the number of samples between each and every trigger. (Note - you will have to throw away your first data point since the Analog Input started before the counter and you aren't synchronized for the first trigger event)
8. read the first 300 samples out of the Analog Input buffer.
9. Subtract 300 from the total counter buffer value and read this out of the Analog Input buffer and throw the data away. (alternatively I think you can save time by simply moving the analog input buffer read pointer instead of actually having to read the data which should save you time)
10. Loop steps 7-9 for as many trigger points as you want (in your case I believe this is 10 times).
11. Clear the Analog Input Operation
12. Clear the Counter Operation

Good Luck,


-Christer
0 Kudos
Message 2 of 3
(2,520 Views)
Hello R. Chiu-

In addition to the method that Christer described, you can also use two counters to generate the sample clocks for you. In this scenario, you would use one counter as a retriggerable single pulse generation, which would take in your 4 kHz trigger signal and generate a longer pulse upon each trigger. It would then feed in as the GATE of a continuous pulse train generation on another counter which was generating at 5 MHz. The output of this second counter would then be used as the sample clock for your analog input measurement. Once your application is set up this way, your measurement will return only the data you are interested in. Basically what you are doing with the two counters is creating a retriggerable finite pulse train generation. I can't remember what examples ship with NI-DAQ, but you might find some helpful code to get you started by searching the development library.

I hope this helps!
gus....
0 Kudos
Message 3 of 3
(2,507 Views)