Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use digital input to trigger analog input acquisition?

Hi bawuer2,

 

As Christian pointed out, the NI Examples are exactly what you need to get started with your program.

 

As far as the tables are concerned, they should be built just like a 2D array, so you can simply acquire all of your data in the loop, and then format the tables afterwards.  I’ve attached a small example of how a table can be built like the one you’ve described.

 

Best regards,

 

Ed W.

0 Kudos
Message 11 of 19
(2,321 Views)

Hi Brandon,

Part of the reason why I believe your code is running slowly is because you are continuously creating and destroying your tasks.  Typically you would create the task outside of your loop and close/clear it after the loop as well.

As I understand it, you would like to acquire a single point of data each time you see a rising edge from your digital signal.  This is generally done by running a continuous or finite timed acquisition.  You would connect the digital signal to a PFI line and specify the PFI line as your external clock.  This should only require one loop(not multiple nested loops).  This is assuming you would only like to acquire 1 point for each rising edge of the digital line. If you need to acquire multiple samples for each digital edge then the retriggerable option that Christian suggested would be the way to go. Note that the finite retriggerable option requires 2 counters. 

If you must provide a clock to your external device, you can set up a counter frequency output.  This task would be in the same VI but would run independently of the analog task. Take a look at the Acq.&Graph Voltage-Ext Clk.vi example as well as Gen Dig Pulse Train-Continuous.vi.

As for working with the table... You can use an Invoke Node to specify which cell to write to.  One way to do this would be to use the Quotient&Remainder function.  You could increment a number each time you receive a sample.  Then you can use the Quotient&Remainder function to divide by 64.  The quotient and remainder would be used to specify the row and column to write to.  Depending on the order you choose the data will be written in rows or columns of 64.

If these suggestions do not work for you please post back with the problems or errors that you are having.

Hope this helps.

Jennifer O.
Applications Engineer
National Instruments

0 Kudos
Message 12 of 19
(2,316 Views)

"As I understand it, you would like to acquire a single point of data each time you see a rising edge from your digital signal.  This is generally done by running a continuous or finite timed acquisition.  You would connect the digital signal to a PFI line and specify the PFI line as your external clock.  This should only require one loop(not multiple nested loops).  This is assuming you would only like to acquire 1 point for each rising edge of the digital line."

This is what I did.  In my code attached I have attached the top two lines send the two signals that I want.  The third one reads in the analog line.  I want it to have it read in one sample everything the external sample clock goes high which I think is what I have.  The waveforms are in real time (it seems that there is no delay) however I do not get the number of samples at the speed of the sample clock.  For example, my sample clock would be running at 138kHz which would mean that my analog read while loop should run 2170 times per second (138k/64) because it reads in 64 samples at a time.  But it seems that it runs much slower when I monitor the while loop iterations.  Am I missing something or is there anything to speed it up?  Thanks.

0 Kudos
Message 13 of 19
(2,296 Views)
It may be becasuse I need to top two lines (of code) to be synchronized and they aren't.  I need the rise and fall of the top line to be in synch with the fall of the second line.  I couldnt ever seem to get them synchronized correctly.  The user input the number of line scans per second they want and then this is converted to the high and low time of the second line that should yield this rate.  I then have it to calculate the high and low time of the top line based on the second lines high and low time.  How can I synch them corretly?  Any suggestions on this post or my one above?  Thanks
0 Kudos
Message 14 of 19
(2,289 Views)
I do have some suggestions for you.  To synchronize two counters you will want to trigger them from the same source.  The type of trigger you use will depend on your hardware.  Please read Hardware Counter Start Trigger for Counter Synchronization for more information on counter synchronization.
 
There is a lot of extra code in your VI which could be causing the VI to slow down.  You can determine if this is a problem by monitoring the number of samples available on your analog channel using a DAQmx Read Property Node.  If the number of samples available continues increasing there is a problem with the code not being able to run the loop fast enough.  If the number of samples is not increasing at a fast enough rate, you know that you are not getting edges quickly enough on your PFI line that you use as a sample clock.
 
I spent some time working with your code to understand what you are doing and I made a few modifications that I think may help.  Could you post which version of LabVIEW you are using so I can attach the VI in a format you can open?
 
Regards,
 
Jennifer O.
0 Kudos
Message 15 of 19
(2,278 Views)

Yeah I'll take a look at that information , thanks.  I am using LabVIEW 7.1.  but I also have an evaluation copy of 8.2 for another couple of days if you cant convert it.  I worked on it today again and I think but I am not sure that the lower number of samples is because of the fact that the two counter outputs aren't exactly synchronized but I got very close to synching them so I can get the sampling rate close enough to what I should be getting.

However, it seems that if I go above a certain sampling rate (about 5000 line scans per second) the waveforms begin to become delayed.  Before I couldnt get above 3000 line scans per second without delay but I changed the number of data points in the waveform buffers to 200 and I made them have a greater amplitude range.  That seemed to help.  Also, in case your wondering I am using a computer with windows xp, 900MHz processor, and 512MB of RAM.  Thanks for all of your help.

0 Kudos
Message 16 of 19
(2,272 Views)
I just tried to insert the DAQmx read available samples and it doesnt seem to work.  It stays at zero and I cant get any data points on the charts.  Any suggestions for getting that to work?  Thanks.
0 Kudos
Message 17 of 19
(2,263 Views)
I figured it out.  I was trying to get a sampling rate above that of the PCI card I had so the waveforms were delayed which makes since.  I also got the snchronization down pretty good so I dont need help with that.  If you could still post the code you edited for me that would be much appreciated because I can change some things that will help make my program run better.  Thanks.
0 Kudos
Message 18 of 19
(2,249 Views)
Glad to hear you have solved your timing issue.  When the task is set up, if you wire the error cluster you should receive an error or warning that you are exceeding the capabilities of the card. You can use the following code as a guideline to reorganize your code. If you have the synchronization of your counters working, you should keep that portion of your code the same.  A couple of areas in the code to look at are: 
 
1) The loop in the counter tasks which checks the task for errors and stops it if one occurs
2) The simple error handlers to display the error
3) The stop conditions for the while loops
4) Since the analog input and counter tasks run independently, you can use a "Diagram Disable" function to temporarily disable the analog/file writing portion of the code and run the counters only.  This is helpful for debugging the counter synchronization.
 
Note that I changed the terminal names (i.e. dev1->dev2) to work with the hardware I have, and you will have to change them back if you wish to test the code.  The code is written in 8.2.
 
Regards,
 
Jennifer O.
0 Kudos
Message 19 of 19
(2,227 Views)