LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Threshold should be held for 2sec before triggering

Hi,

 

I am trying to trigger a stimulator from Labview when the signal acquired reaches a particular value. Now, the value should be held for 2 seconds before I send the trigger. I am unable to program a code to check if the value is held for 2 sec.

 

Any suggestions?

 

Thanks.

Priya.

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

Hi Priya,

 

Thanks for the post and I hope your well today.

 

What aspect were you having problems with, the acquisition of the signal, the analysis of the data to test for the 2 seconds or the outputting of the trigger?

Also what hardware are you using?

 

What I would suggest doing is have a loop performing your continuous data acquisition of your input signal - if it's a slow rate, then just in the same loop update a shift register with a count. If you have a sample rate of say 100Hz, for 2 seconds you'd expect 200 Samples to be high. So if you have some code which updates a shift register overtime it gets a high, but reset it is its a low. Then just have a compare function so when shift register value is = to 200 then output trigger.

 

If you rate is pretty quick - then I would suggest using a producer/consumer design pattern - which involves a second loop to perform the comparison on the acquired data.

 

So in summary,

1. Acquire DAQ task

2. Update Shift Register

3. Compare against number of samples high for period require

4. Output Trigger

 

If you can give some more information on your application and the issues you were having then I'd be more than happy to help you further.

 

Thanks,

Message Edited by Hillman on 04-07-2009 08:37 PM
Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 2 of 7
(2,990 Views)

Thanks! I did exactly that. I had the trigger part working. I just had problem with the shift register and trying to find the values. However, i think now it works. I already tested the trigger...it works. The 2sec hold part, I will be testing real time tomorrow. Hopefully is works.

 

I am sampling my data at 2000Hz so 2 sec meaning 4000 samples. So I ran a for loop for 4000 samples, got the threshold index from the Basic trigger detection vi. I am just concerned abt the timing. Will it finish checking pt. by pt. in that 2 sec or will there be a delay?

 

Thanks. I will probably post my code later to ask for suggestions to improve it.

 

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

Hi Priya,

 

Thanks for the update.

 

Please do post the code if you wish - I don't mind taking a look at it *and nor the community. 

 

So was your question, when acuiring your samples using the hardware timed acquisition will there be a delay in when the signal has been high for 2 seconds and your code working it out and sending a trigger? The answer is most definetly. But you can do lots to help reduce the time. 

 

Firstly, it depends if you're running on a windows machine or a real time target?

Secondly, efficent code - which is a quick as can be to do the looping/logging/comparing. 

But I guess just real testing will show you the delay.

 

Thanks, 

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 4 of 7
(2,961 Views)

Hi I tested it out and it didn't work 😞 I had two conditions...one where in it trigger after the value reaches some %below the max and the other when the max value is held for 2sec (the max value or a value greater). The first one works but the second code doesn't.

 

Also in my DAQ assistant - whats the difference between the frequency and the no. of samples. I see that the data goes into the loop as blocks...so n (the no. of samples that i specify in my DAQ assistant) number of data go into the for loop...is that why I am having a problem?

 

I have posted the code (both the conditions). Please let me know how to improve it.

 

Also, when I trigger by writing to the Analog output it triggers the first time but not the second. I have to write a 0 voltage to the channel before it triggers again...even if i send a square wave which goes back to zero. I am using a USB2008.

 

Thanks a ton!

0 Kudos
Message 5 of 7
(2,950 Views)

I have not been able to look through your code just yet, but I wanted to explain the difference the frequency and the no of samples.

 

The frequency is the rate in (Hz) for which samples are measured from your line and moved to the DAQmx buffer. This is known as the sampling frequency.

The no. of samples is the number of samples (or how large of a chunk of data) is returned every time the DAQ assistant (read) is called.  Therefore everytimethe array that is returned from the DAQ assistant will be a multi-dimensional array that has the number of channels as one dimension and the No of samples in the other dimension.  

 

 

 

 

Charley Dahan

Global Account Manager
0 Kudos
Message 6 of 7
(2,912 Views)
Did anyone have the time to look into my code?
0 Kudos
Message 7 of 7
(2,852 Views)