LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting pulses between time delays

I'm developing a new automated test system to preform test proceedures on our group's electronics.
 
To determine a pass/fail, I have to count the flashes of an LED. I'm running the voltage leads from the LED to a pxi-6259 DAQ-M device in my PXI chassis.
 
The pattern is: 200ms on/off for the "code". ex: code 4 is 200ms on, off, on, off, on, off, on. Codes are repeted until power is disconnected, with a 400ms delay between the on of the previous code and the first on of the next. Please see below:
 
^_^_^_^__^_^_^_^__^_^_^_^__ 
 
The code does not always begin with the 1st pulse as it's timed to specific intervals based on the internal clock.
 
How do I count the number of on pulses between the time delays? I need to be able to differentiate between 4 pulses "code 4" and 5 pulses "code 5" etc.
 
Ideally, I would like to wait for an off cycle, trigger the counter to start, then stop counting with the next off cycle, but what VIs and functions to use?
 
Thanks for the help.
 
Software: NI Developer's Suite, no special packages
0 Kudos
Message 1 of 14
(4,858 Views)
I think the easiest approach is to use a buffered semi-period measurement technique with one of your counters, provided the signal can be made TTL-compatible.  Then the hardware will buffer up that whole sequence of on and off times, and you can easily go through the array to identify the long delays between code cycles.
 
An alternative is to simply sample your LED voltage as an analog input channel.  I'd probably pick a sample rate between about 40 and 100 Hz (25 to 10 msec per sample).  This will give you multiple samples per LED state, but will still keep the overall amount of data quite low.  The transitions should be easy to find by feeding the full array of AI samples into a "greater than" comparison function along with the mean value of those samples.  You'll get a boolean array with T for high and F for low.
 
From there, there's some fairly straightforward array processing to find the first long delay and then determine the # of on/off cycles until the next long delay.   Hope this helps you get started...
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 2 of 14
(4,828 Views)
Thank you so much for your help. I was finally successful in sampling and counting pulses!
 
Now I'm still stuck on counting pulses between pauses.
_____^^^^^^^^^_____^^^^^^^^^_____^^^^^^^^^
^ 2s   ^ count ^  2s  ^ stop count
 
 
1. if time between 2 edges (rising-rising, or falling-falling) = 2 sec, start counting positive pulses.
2. When time is between 2 edges = 2 sec, Stop counting and report count
 
I am getting my data through an analog input on my PXI-6259 M series with a SCC-68 connection box.
0 Kudos
Message 3 of 14
(4,792 Views)

The "Basic Level Trigger Detection.vi is nice because it can be set to detect either positive or negative going pulses, and the level can be set by you. Basically it functions like a trigger on an o'scope.

 

Look in your functions under Waveform_Analog waveform_waveform measurements_Basic Level Trigger Detection, from there it is pretty simple to detect your upward and downward edges.

 

Chris

One should welcome adversity as an opportunity to excel.
0 Kudos
Message 4 of 14
(4,787 Views)

Thank you Chris.

I can now count pulses in my sample, but I'm having a hard time pulling the timestamp for the value from the dynamic data type. Here's an idea of what I'm doing:

Analog data (DAQAssistant): Dynamic data into a for loop converted to a dbl and using the iteration "i" of the loop indexing out one value per loop iteration, I take that value and put it through the trigger which then tells me if it's over or under the level.

When the value is under the level (produces a false), I want to record the time stamp of when that value was originally sampled. Then I want to compare it to the time of the next value above the level (produces a true) to determine if it's a 2 second pause or a 500ms pause.

How do I pull timestamp data from the dynamic data?

Thanks for the excellent help.

0 Kudos
Message 5 of 14
(4,764 Views)

Hi GradMarch,

From the dynamic data type (DDT) you can get the time stamp by converting the DDT to a waveform using the function “Convert from Dynamic Data” and selecting “single waveform” as the resulting data type.  From there you can use the get Waveform components to extract the “t0” (first time stamp), the “dt” (step) and the Y values. As you can see elements in the “Y” array are going to be separated by “dt”.  Remember that “dt” is the period of your rate (i.e. 1 / rate).

You can either build an array where one column is the data and the other column is the timestamp but this will slow down the while loop and also will take a little bit of programming. The best way of doing it is using the position of the data on the array as the stamp remembering that each position is an increment of “dt” and “t0” is when the first sample of that array was read.

I have also included the "Basic Level Trigger Detection.vi" that triggers a boolean every time the waveform crosses the "voltage level". This voltage level can be change in the block diagram to meet your needs. The timestamp of the occurrence of this event is also and output of this Level Detection VI.

 

For more timestamps examples go to NI Developer Zone and type timestamp in the search field.

I hope it helps

Message Edited by Jaime F on 11-01-2007 05:23 PM

Jaime Hoffiz
National Instruments
Product Expert
Download All
Message 6 of 14
(4,746 Views)

 

Thank you everyone for your continued help. I thought I had this all figured out, but now I'm getting a very strange error.

Error -20308
occurred at  "NI_MAPro.lvlib:ma_ptmFetch.vi:3"
when called from "NI_MAPro.lvlib:Pulse Measurements N chan.vi:2" 
(waveform index 0 of 1)

Possible reason(s):

Analysis:  The waveform did not cross the mid reference level enough
times to perform this measurement. Check the signal length, reference
levels, and ref level units.

Here is a picture of the waveform with the error box, and below you'll find a screen capture of my code.


The program logic is as follows:

If the data crosses 2V proceed to analysis, if not, pass a zero to the counter indicator.
2V seen --->   If the dt of the pulse is 2 sec pass which pulse#  to count loop, else pass zero to count indicator
2sec seen ---> starting at pulse#+1, if dt is between 0.3 and 0.6 count, if over 2sec end and pass pulse count to indicator.

Thanks for any help you can give me. It's been working on all other pulse counts (2,3,4) I guess 5 is different.

0 Kudos
Message 7 of 14
(4,643 Views)

Hi GradMarch:

I have done a simplify version of your code; to simulate the issue, as you can see it works fine. You need to check you reference levels. Does it work a couple of times and it stops working on the last iteration? Because if that is the case, what I think is happening is that your last chunk of data is not crossing the reference levels needed to make the measurements, something that you might do is change the “ref units” to percent and check the output, this will help you debug your issue.

1. Block Diagram

2. Front Panel

I hope it helps



Message Edited by Jaime F on 12-07-2007 02:47 PM
Jaime Hoffiz
National Instruments
Product Expert
Download All
0 Kudos
Message 8 of 14
(4,620 Views)

Jaime,

This piece of code is embedded inside a while loop which checks for the 5 downward pulses on every iteration. For about 3 hours, this code runs perfect every 10-12 seconds in this loop. After 3 hours, when these 5 downward pulses are expected to apear, the error ocures and kills the test.

I have tried this with both the percent and the absolute (per your idea) and have seen the same issue. I have now changed the test so that it will start checking for the pulses after 3 hours (when they should not be present) in hopes of finding the pulses at about 4 hours into the test when they should be apearing.

Thanks you for you're help. Please don't hesitate if there is another idea.



Message Edited by GradMarch08 on 12-08-2007 05:51 PM
0 Kudos
Message 9 of 14
(4,597 Views)

This issue is still present.

Maybe the better question is: How do I get it to pass the error so I can handle it rather than fatally ending my program?

0 Kudos
Message 10 of 14
(4,566 Views)