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: 

Count rising edges between two pulses

Solved!
Go to solution

I'm looking for either code or hardware that will help me with a gate circuit.  We will have 2 pulses on the same channel, and I need to count pulses from a separate line during the time between the 2 pulses.  Our existing systems utilize some external hardware (essentially a flip flop) to provide this, but I'm looking for a way to get rid of this external hardware.

0 Kudos
Message 1 of 9
(3,575 Views)

Dear neilsontr,

 

What you have described here is a little confusing. Can you please sketch out or draw a diagram of what you are trying to accomplish? Also, what is your current hardware setup?

 

Regards,

Alyssa H.

National Instruments

0 Kudos
Message 2 of 9
(3,517 Views)

here is a quick hand sketch. 

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

This can be a (mostly) straightforward Counter task.

 

A method that's pretty universal for just about any NI board with counters would be to configure a Period measurement task, setting it up with Units="Ticks".   You'll need to specify the Gate signal in your sketch as the signal whose period you want to measure.  Then the sorta tricky part is that you need to identify the Counter Input signal in your sketch as the counter's timebase source.

 

To get just 1 measurement, don't make a call to DAQmx Timing.vi before starting the task.  To get a buffer full of continuous measurements, *do* call DAQmx Timing to set up a buffer and configure it as "Implicit (Counter)" .  Note: different era boards have different counter behavior for buffered period measurement.  Newer ones return the 1st sample at the end of the 1st *full* interval when the 2nd Gate edge arrives.   Older ones return the 1st sample at the end of an intial *partial* interval when the 1st Gate edge arrives.

 

There are other methods that might be simpler conceptually but they only work on newer boards such as the X-series MIO boards.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 9
(3,492 Views)

This is also fairly trivial to do with just code and two analog input channels.  Just set some voltage threshold.  If you go above that threshold you are "in pulse", dropping below it becomes "out of pulse".  Increment your counter every time you detect from in to out.

 

I'm not at a computer with LV right now, but in pseudo code


For (each element in data array)

  {

   If (element < Threshold && InPeak == true)

      PulseCount = PulseCount + 1

  else 

  if (element > Threshold && InPeak == False)

     InPeak == True

  }

 

Just store "InPeak" and PulseCount in shift registers and have a for loop every time you read from your analog input.  Only process for loop in between your two trigger pulses (that you'll detect the same way!).

Message 5 of 9
(3,489 Views)

I like the suggestion from BowenM.  In my experience on the forums, it's a better match for the way most users find most natural to think about these problems.  I just happen to like counter/timers kinda a lot.  Smiley Happy

 

I'm pretty sure his pseudo code will need to be tweaked some, but the basic concept can work and most people will probably find it easier to understand.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 9
(3,474 Views)

We currently do not have any hardware specified, I'm working on that now.  Our existing systems have used M series DAQ (or whatever the standard multifunction daqs are/were).  Those systems had external circuitry that we developed, I'm trying to move away from custom hardware if I can.  I can move to any sort of DAQ available now, but would prefer to keep it out of RIO so that I don't have to start over with our programs (and I have no experience with RIO).

0 Kudos
Message 7 of 9
(3,472 Views)

We can certainly do this, and have done this (essentially a software trigger turned on and off by that line).  For this particular situation though, our preference is to make the gate external and not software.  There is some concern of accuracy if it is essentially turned on/off via software.

0 Kudos
Message 8 of 9
(3,467 Views)
Solution
Accepted by topic author neilsontr

Kevin is correct - I have nothing in my psudo code to set InPeak == False, but I'm sure you can figure that part out 🙂

 


@neilsontr wrote:

There is some concern of accuracy if it is essentially turned on/off via software.


The software should be easy enough to validate.  I see no reason to have any concern at all with this method.  To put this into perspective I wrote a quadrature encoder demodulator using (almost) the exact method I described above.  I was able to count all 4 edges, direction, and frequency extremely accurately up to ~20 kHz pulse trains.  The only limiting factor was the maximum rate of the AI card I used.

 

 

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