LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run Counter for Specified Time

Hi All,

 

Sorry if this is a total newbie question. I searched but did not find.

 

I'm writing the LabVIEW code for a mass spectrometer and one of the functionalities that would be really great is an elegant way to find the number of counts (TTL pulses sent to the AI, which represent ions) in a specific time (usually 0.1s). I can think of sloppy ways to implement this code, but I feel like I'm missing a much more elegant and simple way to do this.

 

Thanks in advance!!

N.R.

0 Kudos
Message 1 of 11
(3,252 Views)

If you have TTL pulses why are you counting with an AI channel?  You can set uo a counter to do this and use buffered counting and gate the time bins from another counter.

The input pusles are the clock and sth second pulse train is the gate of the counter, on each edge of the pulse train on the gate the counts from your ttl line will be buffered.

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 2 of 11
(3,241 Views)

I'm sorry, they're sent to the "ctr0" channel on our NI device (the counting itself works very well), my mistake. I believe it counts versus the HW timer (80MHz?).

 

My problem right now is that I have the DAQ Assistant for the counter in a timed loop, but it isn't really counting for just that loop time; the time "between" loops and to execute other tasks is also taken into account, which could get tricky in the future. I thought I had found a solution when I used the DAQ-Stop then DAQ-Start method to reset the count, but that happens before the loop/sequence completes and causes the problem I just mentioned. I need a way to start the DAQ-Assistant/Counter as soon as it is needed/called in the sequence and then stop it after a set time (0.1sec, for example). Again, not quite sure of an elegant way to do this.

 

Attached is what I am using right now for a two-mass ion counter. The problem will come when the delay time is added for the power supply to ramp up/down according to each alternating mass, which adds extra time and thus variability to the actual counts. Hopefully that makes sense? Attached is what I have so far 😃

 

Thank you so much!

0 Kudos
Message 3 of 11
(3,237 Views)

I don't like express vi's because it is not readily apparent as to what settings are there.  If you double click on the DAQ assistant, you will see a configuration tab with settings at the bottom for Acquisition Mode, Samples to Read, and Rate.  Set the mode to N Samples, Samples to Read to 100, and Rate to 1K.  Then the DAQ will read 100 samples and stop.  If the rate is 1K, a sample will be read every 1 mS (0.001s).  To read 100 samples will take 0.1 seconds (100mS).  So by playing with the combination of Samples to Read and Rate, you can set the DAQ to read for a finite period of time, then stop.  This could also be done with DAQmx functions instead of a DAQ assistant.

Every time the loop iterates, the DAQ will run for 0.1 seconds.  The way you have it set up in your vi, it takes only one readings and then stops until the next loop iteration.  So it does not run for the entire loop duration.  You don't need the timed loop, so replace it by a regular loop or remove it completely.

 

- tbob

Inventor of the WORM Global
Message 4 of 11
(3,227 Views)

tbob, thanks for the great reply! If I understand correctly, I could set the rate to 10 (Hz) (0.1s) and select 1 sample, to get a reading for the number of pulses in 0.1s? (Or same thing for "1 sample HW timed @10Hz", correct?) Thanks again!

0 Kudos
Message 5 of 11
(3,221 Views)

@UNR_CHE wrote:

@tbob, thanks for the great reply! If I understand correctly, I could set the rate to 10 (Hz) (0.1s) and select 1 sample, to get a reading for the number of pulses in 0.1s? (Or same thing for "1 sample HW timed @10Hz", correct?) Thanks again!


Is that the way the counter works?  It gives counts if you specify 1 sample?  I was thinking of DAQ analog inputs when I gave my answer.  A normal DAQ input would take 1 reading if you specified number of samples as 1.  I guess because this is a counter, it counts for 0.1s.  What happens if you specified more than one sample?  Like if you specified 2 samples, would it count for 0.1s, then count again for 0.1s, and give you 2 separate counts?  I'm not that familiar with counters.

- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 11
(3,218 Views)

Apparently, my idea didn't work--it does need multiple samples. My other problem arises from not quite understanding why I can't use the onboard clock for a counter application.. Seems like it should be a lot easier to say "count pulses and tell me how many you get after 0.1 second."

0 Kudos
Message 7 of 11
(3,181 Views)

Couldn't find a way to edit, so I added a time delay in the DAQmx code, but it still seems a little unstable/inaccurate... If only I could find a way to get a more accurate onboard hw clock to do the delay timing?

0 Kudos
Message 8 of 11
(3,174 Views)

There is an example that ships with Labview called Count Digital Events.vi.  You can use Find Examples to find it.  Search for counter.  This is what you need.  Ah what the hell, I've attached it below.

 

- tbob

Inventor of the WORM Global
Message 9 of 11
(3,169 Views)

Thanks tbob! I'll have to check that out when I get back in to work tomorrow. I am not going to make assumptions as to what is in that example, but I do have my events being counted already (wrote a DAQmx subvi to do it). I guess I just need to use an external counter to do more accurate counting? I used the "wait ms" tool to make my counter run for 0.1s, but I'm not sure how accurate that method is. I put a sequence structure in the sub vi, placed start task in the first pane, wait 100ms in the second pane, and both read data and stop in the third pane. I'm not sure how accurate this is for 0.1s.

 

Again, I really really appreciate your help and I'll be sure to check out the example when I get to work tomorrow!

N.R.

0 Kudos
Message 10 of 11
(3,155 Views)