LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Temporarily stop data acquisition by external trigger

Solved!
Go to solution

Dear All,

Being relatively new into programming in LabView I do have a question considering data acquisition and triggering. Searching documentation and forum couldn’t answer my question so far. I am using LabView to make some simple software in giving participants feedback on a task to perform based on their muscle ElectroMyoGraphy (EMG).

 

For clarity:

 

  • Using a NI BNC-2090 with a DAQcard 6024E (alternatively I have available the BNC-2090A with a USB-6251)
  • Using LabView 2011 software package

What I’d like to do is temporarily stop data acquisition when an external TTL trigger pulse is recorded (coming from some external hardware) while performing the requested task. So the task will last for about a minute and throughout this minute the data acquisition needs to be temporarily stopped, time being related to the width of the TTL trigger block pulse, and resumed again.

 

The purpose of temporarily stopping data acquisition is to freeze participant feedback as an external disturbance is presented which we don’t want to show up in the feedback, and thereby influence the task performed.  

Important note: I tried several methods but came across the problem that I don’t want to do continuous acquisition as the buffering seems to delay the feedback which should really be instantaneous. The program it selves works very well using the Express Data Acquisition VI with a Single Point settings (1000 Hz sampling rate), obviously not including the stopping at triggering. Continuous acquisition, however, seems to be a requisite for being able to use proper triggering.

 

Hope anybody can give me a go with any small example or comment!

Cheers,
Mark

0 Kudos
Message 1 of 12
(5,005 Views)
Solution
Accepted by topic author MLVDR

Hi Mark,

 

I've interpreted your post as follows:-

 

- You want to acquire analogue data until an external TTL (0V to 5V) trigger signal goes high.

 

- When this signal goes high, you want to pause data acquisition.

 

- When this signal returns to a low state, you want to resume acquisition.

 

- You have tried to achieve this using the DAQ Express VI.

 

 


 

To acheive this you will need to use the lower level DAQ VIs, so that you can pause a continuous acquistion when a trigger signal goes high.

 

I have written and attached some code that should illustrate how this is done. 

 

You will need to connect your trigger source to a 'TRIG' input on your BNC-2090, and then select this as your trigger source on the block diagram.

 

I hope this is helpful,

Josh E
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 2 of 12
(4,983 Views)

Hi,

 

Thanks for your reply.

 

Your interpretation of the problem is right. 

I did play around with lower level VIs but couldn't work out exactly which properties to use.

 

I did a simple test with your code and although it runs it doesn't show the expected behavior.

It seems to pause when a trigger is received but it only registers one out of many external triggers.

Additionally after some time it gives the E -200279 it tried to read samples which are no longer available.

 

Hence, I am using the 6024E DAQ card and although a lot is posted elsewhere on this forum about how to use 

this card with triggering and DAQ I can't work out how to make it work in my case.

 

Cheers,

Mark

0 Kudos
Message 3 of 12
(4,965 Views)
Hi Mark, The code is set to only trigger off one external trigger signal (i.e. one digital line). How many external trigger signals would you be using to pause acquisition? I will look into this error for you. It is likely that the read loop is not reading in samples fast enough, resulting in samples being overwritten in the buffer before they are read. Different hardware can acquire data at different rates, which could be why it works on my setup and not on yours. Decreasing the wait time in the loop may solve this. Let me know if this helps.
Josh E
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 4 of 12
(4,961 Views)
Sorry, I haven't been fully clear. I do have only one trigger digital line but an external trigger occurring roughly each 2 seconds.
So each 2 seconds acquisition should be paused. Now it does only read about one in about 10 / 15 consecutive external triggers on that single line finally giving the error message.
 
I did play with the waiting times and type of acquisition. I tried to decrease the wait time but found out that it can only be 0 or 1 (or higher), which makes sense with the manuals. So I tried 0, which combined with a higher sampling rate made it work without giving errors. But now it doesn't seem to register any trigger at all.
 
I am sure the trigger is present, so there is something in the acquisition settings that makes it not working well. I will do some more tests and get back to you asap.
 
Thanks again,
Mark
 
0 Kudos
Message 5 of 12
(4,957 Views)

Hi,

 

The good news is that with playing with the sampling rate and the samples per channel setting I have been able to get the code well running without error messages (so far..).

 

However the second part of my initial question still remains. There is a significant delay between the time the actual trigger is generated and the acquisition is paused. An delay up to 10 msec would do for me but now it is much longer. What setting determine the delay? (I guess it has to do with samples per channel and sample rate as well).

 

Hence as I mentioned in my first post the initial code, without the pausing, worked well only with single point acquisition in the express VI whereas the continiuos acquisition gave a significant delay between action --> reaction as well.

 

Hope does makes sense and someone could clarify on this,

 

Mark

0 Kudos
Message 6 of 12
(4,936 Views)

Hi Mark,

 

Just a few questions;

 

- Can you send me your code?

 

- Are all of your external trigger signals connected to trigger inputs on your NI BNC-2090?

 

Thanks

 

Josh E
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 7 of 12
(4,920 Views)

Hi Josh,

 

I am just using the code you attached earlier. Only played with sample rate and samples per channel.

Happy to send it but it is exactly similar to what you've send me. My full code has exactly the same problem

so it doesn't really make sense to send it will take you some time to get through it.

 

I do have one single trigger channel connected to the TRIG input on the BNC rack. A trigger comes in roughly each 2 seconds

but there is a significant delay between receiving the trigger and pausing the acquisition.

 

Thanks a lot for the effort you put into it.

 

Regards,

Mark

 

 

0 Kudos
Message 8 of 12
(4,914 Views)

Hi Mark,

 

I will look into this further. With your hardware you shouldn't be getting a delay as long as 10 msec, so it is likely to be something in software that is causing the delay.

 

I will post back when I have some results.

 

Regards,

Josh E
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 9 of 12
(4,901 Views)

Hi Josh,

 

I have been working on this the last few days and solved part of the problem.

 

The good new is that LabView does pause immediately now on each trigger coming in on the TRIG input.

What I changed to your code is change the acquisition type of the Read VI to Analog Input --> 1 Chan, N Samples.

Additionally I had to remove the Wait until ms function. 

 

With the following settings:

Sample Rate = 10000;

Samples per Channel = 10000;

Number of samples per channel = 1000;

It works perfectly!

 

The delay in the Analog Input, 1 Chan, 1 Samp likely originates from a buffer which is created as read out isn't fast enough to keep up

with the acquisition. Therefore it always lags when a trigger is applied and there is a significant delay. 

It raises however a view questions on what is the best way for me to acquire my data as for me it is of huge importance that the feedback is real time, so the sampling

frequency being as high as possible.

 

1:

The solution proposed is effectively a massive downsampling, isn't it? As I can only process single values in the rest of my code, I need to extract a single value from each array (length: 1000) acquired

decreasing my sampling frequency effectively to 10 Hz. Agree?  (1 sample processed each 0.1 sec)

 

2:

I had to remove the Wait Until ms function from the while loop in order to avoid getting the E-200279 (Samples no longer available) error. This is in all cases

were I try to use single Sample Acquisition. What is the purpose of this function? My feeling is that it only messes up the HW timing coming from the Sample Clock and consequently fills

the buffer when it waits, leading to the observed error.

 

3:

Final and most important question: What would be the most efficient way for me to acquire data taking into account the comments made before?

I'd like to acquire single samples with the highest possible sample frequency (preferably around 2000 Hz).

 

Hence, this all has been tested in the plain code (as you send it earlier) and my full code. Behavior is similar.

 

Regards,

Mark 

 

 

 

0 Kudos
Message 10 of 12
(4,888 Views)