LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Increase Speed of Sequence Structure

I have been battling this problem for a week, and I keep think I am getting somewhere and then get caught out due to my lack of labVIEW experience.
I am using simple push to break switches and wish to find the time between taken between these switches.
I am aiming to get 10s of microsecond accuracy

I wish to use the first switch as a trigger for the system so that this is regarded as time zero.
Attached is my current vi, which has undergone many changes in the past week.
In this instance I am using a structure to continuously look at the trigger channel until it reaches a threshold voltage. When this occurs it triggers the aquisition of all other switches. (I am currently just recording this so I can look up in excel and find the time switches are made, however I eventually want labview to do this. Any help on this would also be useful). I have put a crude timing mechanism in to see the time difference between triggering and data aqcuisition starting and this give a 32 ms difference. Ideally I want this in us.

So my main question is:
Is my vi the right way to go about what I want to do? If so how could I speed up the structure.
If not what ways would you suggest for me to get the results I want?

Regards
T

0 Kudos
Message 1 of 10
(4,140 Views)

I am not sure I understand what you are trying to do, so let me rephrase it.  At some point in time, you have a switch that is being pressed.  You wish to measure the time between that switch being pressed and other switches being pressed accurate to about 10µs.  If this is the case, then you need to rethink how you are approaching the problem.  Modern operating systems, such as Windows and Linux, are multi-tasking and do not do time intervals too well.  There are too many things which can interrupt your timing.  As a broad rule of thumb, do not depend upon the operating system for timing any better than about 50ms.  You can get microsecond resolution by using the high performance counters of most processors, but interpreting the result can be difficult.  In your case, there is a far better solution - use your DAQ board.  It was designed to do such things accurately and repeatably.  You have several options:

 

  1. Use the timers to time your button presses.  These are limited to digital TTL levels (0-5V), and most DAQ boards have two of them.  If you only have three buttons, trigger both timers with the first button, then read the value after the second button press.
  2. If you have more buttons, or you have non-TTL levels, use the analog input channels in parallel to get your data.  Use your first button on the first channel to trigger your operation (you may want to use pretrigger points to get a good waveform).  Use additional channels for additional buttons.  Take data for a fixed time period or until all buttons are pressed.  Fetch the waveforms into the computer and analyze for when the buttons are pressed to get your timing.  Note that most DAQ boards only have a single analog to digital converter, so the channels are scanned.  This results in a small time offset between each of the waveforms which is reflected in the waveform timestamp.  You will need to accomodate this in your calculations.
  3. Some DAQ boards have clocked digital input lines.  You can use these in a manner similar to the analog method in item 2 if you have TTL signal levels.

If you need more information, please let us know what type of DAQ board you are using and the signal levels of the switches.

0 Kudos
Message 2 of 10
(4,124 Views)

Thank you for this response.
I have been using the second approach. The restraints leave me only able to grab 10s of data,(any longer and I get error messages) which is fine because I require less than 1s.
However I need to create a trigger by using the first input, which so far are surpassing my LabVIEW skills.

I am using a cDAQ-9174 with two 9223s for my switch inputs.
Currently the switches that I am using are as basic as possible and two wires connected/disconnected and I am analysing the voltage for these. (This will change when I get round to experimentation)

 

As you can see from my vi. I am using a somewhat brute force method to analyse the data acquired but it does the job. I am sure there is a much neater way to do this.



0 Kudos
Message 3 of 10
(4,083 Views)

@T-Pope wrote:

 

...As you can see from my vi. I am using a somewhat brute force method to analyse the data acquired but it does the job. I am sure there is a much neater way to do this.


this?

Spoiler
time2.png

or that?

 

Spoiler
time.png

 

Message 4 of 10
(4,059 Views)

Use a DAQmx Trigger.vi from the DAQ palette to set up triggering on your first switch channel.  I would recommend a few pretrigger points.  The following code may make your switch location finding a bit easier.  It relies on the threshold VI from the array palette.

 

FindingTriggers.png

Message 5 of 10
(4,042 Views)

I will attempt to use the DAQmx trigger, however I tried to use this before and I didnt think it worked with my hardware.
Would this not also add a short delay into the acquisition? even a small change could affect my results.

Thanks to both of you for your input, I will implement these ideas next week.

0 Kudos
Message 6 of 10
(4,031 Views)

Thank you for again for the help.
I have implemented a more elegant solution to my brute force method.

I am still struggling with creating a trigger to start recording the data though.

Ideally I want to do this from the initial switch, which is an analog input. The trigger.vi does not seem to accomodate this with the 9223 module.

I have tried using the DAQ assistant trigger and gate and can use this to get a trigger from this analog input of the ni9223.
How am I able to do this but not able to do it with the trigger.vi 

 

I do have a ni9401 module, however I am not sure I understand completely how to use it and therefore are hesitant to introduce it.

Any input would be appreciated

0 Kudos
Message 7 of 10
(3,992 Views)

Attached is a VI with the triggering added.  I believe your confusion stems from the difference of the Start trigger and Reference trigger.  The Start trigger starts the clocks and data acquisition mechanism.  This is when the DAQ boards start actually taking data and buffering it, but not passing it to your code.  This is usually set to None, so the DAQ board starts as soon as it is initialized.  The Reference trigger is the one you want.  When the reference trigger is satisfied, the DAQ board acquires the number of points you specify, prepends the pretrigger points it had buffered, and passes that back to your code so that the Reference position is the trigger point you specified.

 

Hopefully this helps.  Good luck and let us know if you need more assistance.

0 Kudos
Message 8 of 10
(3,958 Views)

Thank you for going to the effort to write this, unfortunately I cannot get it to run.
I get an error from the trigger.vi with reference to the source being used.
Firstly it does not give me the drop-down box menu that is usual when supplying an input.
It does not accept any of the analog inputs from my 9223 modules and supplies me with the error:

 

Error -200265 occurred at Property Node DAQmx Timing (arg 1) in Time of arrival with sample rate with trigger (1).vi

Possible reason(s):

An attempt has been made to use an invalid analog trigger source.

Ensure that the trigger source you specify matches the name of the virtual channel in the task or matches the name of a non-scannable terminal that the device can use as an analog trigger source.

Property: Ref.AnlgEdge.Src
Corresponding Value: cDAQ2Mod1/ai0

Valid Choices: none

Device: cDAQ2

Task Name: _unnamedTask<1>

Have you encountered this before?

0 Kudos
Message 9 of 10
(3,919 Views)

You do need to get the source exactly correct and there is no real help to do so.  I filled it in based on the input channels of your system as I got them.  In general, it should be DeviceName/ChannelName.  You can get both of these from the list in your I/O name control you use to initialize the analog acquisition.  Or you can get them from MAX.

 

I tested my code with simulated devices, since I do not have your hardware.  It is possible that this will not show the errors you are seeing.  I did see a similar error when I got the format of the trigger channel wrong, but I also got suggested Valid Choices (which, unfortunately, were not actually valid, so I would approach this with a grain of salt).  In any case, you have exhausted my meager knowledge of DAQmx.  I would suggest you repost your question with the latest VI on the DAQ forums.  You will probably get a response very quickly.  My apologies for not getting you further.  Good luck!

0 Kudos
Message 10 of 10
(3,897 Views)