From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Input Triggers Counter Output With Delay

Solved!
Go to solution

Hi!

      I'm currently using a PCI-6251 DAQ board with a BNC 2120 connector block.  I have a VI (the one that is attached to this thread) that will basically take an analog input signal, and produce digital pulses from the counter output at each trigger instant.  I'm also able to set a series of delay values such that the delay will automatically update itself every at user-specified intervals, or when the stop button is pressed.  I'm wondering if there is anyway to modify this program such that the delay value will change at each trigger instant.  So for example, at the first trigger a pulse is produced with 0 seconds of delay, then immediately when the next trigger instant is reached, a pulse will be produced with a delay of 0.1 second, etc...  And I want the series of delay values to keep looping.  I tried to use my current VI, with the time to stop each iteration to be less than half the period, so theoretically it should go to the next delay value at the following trigger instant.  Then I tried to put a while-loop around the whole thing to keep the task going, but it doesn't seem to work.  I have attached a screen capture of my attempt, please let me know if doing this is possible, thanks!  To see what each part of the VI does in the screen capture, please see the VIs attached, thanks!

 

P.S. for the VI that's attached, the analog input signal is 281Hz, the pulse width is 2.5% of the period, and the delay is in steps of T/20.  

 

Untitled-1.png

0 Kudos
Message 1 of 9
(5,099 Views)

In your program you have a few things that will cause it to error out.Currently it is not working because you actually ave an error being thrown from the AI Star.VI

 

1.  Currently you do not STOP your AI Task  once the for loop is complete.  You then try to start that AI task again even though this task has not been stopped yet.  I've added a stop there (not clear) and that rectified one error that was produced.  

 

2.  Although this is not needed I've added an error handling technique to your VI which whenever there is an error thrown the VI will quit th inner/loop. 

 

3.  I've gotten rid of the feedback node at the end of yourprogram as it is not needed and cleans up your program

 

 See the attached screenshot for more details on this

 

This should get you up and running. 

 

Block 9219 Acquisition.png

Charley Dahan

Global Account Manager
Message 2 of 9
(5,080 Views)
Thanks for the help Charles.  Since I am able to display of the analog input signal on a graph, is there anyway for me to display the counter output signal as well?  I'm not sure how to go about doing this, any help would be greatly appreciated.  Thank you!
0 Kudos
Message 3 of 9
(5,067 Views)

You cannot show the exact output without wiring that signal out to some analog/digital input and "digitizing" it.  To do this, hard wire the output of the counter (CTR0 out = PFI 12) to the Digital input or analog input that you choose.  Setup a task corresponding to the acquisition that you desire and route the signal from PFI12 to the necessary pin for the acquisition. 

 

 

 

Charley Dahan

Global Account Manager
Message 4 of 9
(5,051 Views)
Thanks again Charles.  I just have one more question.  Is there anyway to put a FFT plot in the code to show the FFT of the input signal?  I tried to do this, but nothing is showing up on the plot, but if I just make a new VI and using the DAQ Assistant to acquire the signal, then wiring the FFT subVI supplied with the LabVIEW program, I can see the FFT graph.  Why is it I am not getting a FFT graph if I just take the "data" output from where the "waveform" is in the innermost while loop?
0 Kudos
Message 5 of 9
(5,046 Views)
Solution
Accepted by topic author P00rColl3geBoi

No worries,

 

Please see the attached  block diagram image.  It is important to wire in a constant to Number ofsamples to Acquire terminal on the DAQmx Read.VI.  This will force this function to wait until there are that many samples available in the buffer.  In my example you will get 1000 samples every second (because my rate is 1kHz).  and those 1000 samplesare put out directly to the FFT.  What was happening with you example is that because you did not specify the number of samples to read, it defaults to (-1) which means that the DAQmx Read.vi function will pull any data that is available in the buffer at that time.  Therefore if you only had 2 samples in the buffer your FFT will only have two samples to average and therefore it will fail. Try this and it should help!

 

FFT DATA.jpg FFT settings.jpg

Charley Dahan

Global Account Manager
Message 6 of 9
(5,029 Views)

Thanks again Charles, it seems that the "read waveform" portion of my VI is actually reading the signal from the counter output even though the signal looks like the input analog signal.  I've already got the sampling rate and samples to read portions wired for the input analog signal, so what you are suggesting is for me to increase the sampling rate and samples to read for the counter output portion.  This seemed to work, but I only want to generate one pulse for each trigger instant, so I cannot have anything higher than "1" for the counter output clock.  Is there any way for me to view the FFT of the input signal without changing anything in the counter output portion of the code?

 

Edit:  Sorry, I had misread your original post.  I missed the part where you said to wire that "1000" to the read.vi portion.  I'm gonna go fix that right now and see if it'll work better. My apologies

Message Edited by P00rColl3geBoi on 06-16-2009 02:12 PM
0 Kudos
Message 7 of 9
(5,026 Views)
Charles, that worked perfectly, and I've learned a lot because of you.  Thank you so much!
0 Kudos
Message 8 of 9
(5,017 Views)

Hello Charles,

 

Is it possible to get the code? I am quite new to labview, I am trying something similar as in this example.

 

Thaks!

 

 

Block 9219 Acquisition.png

0 Kudos
Message 9 of 9
(3,161 Views)