LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need a simple counter

Hey folks, fairly new to Labview and I need a simple counter.

 

I'm attempting to monitor circuit breaker contacts for bounce during a physical shock test.

 

Basically if the input voltage goes to zero for greater than 20ms I need to post an indication.  I have most of the vi built, I just need a counter/timer that will zero with a boolean false input and increment once every millisecond on a true input.  Then I will test the output for greater than 20.  I'm sure this is a simple task, but I'm stumped.

 

Thanks in advance for any help.

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

This is pretty simple, although if you're not running on a real-time operating system you may have trouble achieving a consistent 1ms loop.  Have you written any code yet?  You'll need a while loop (or possibly a timed loop) with a shift register to store the counter value, a boolean input, an increment, probably a "Select."  Give it a try, and if you're still stuck, post your code.

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

Hello Dgonz

From your description I assume you don't really need to implement counter, but you just need to check if measured value is equal to 0 for more than 20 ms. Here's a quick draft:

value.png

 

As nathand said, constant 1 ms timing in the loop is hard to achieve on non-realtime system. 20 ms seems far more reasonable.

 

Could you post more informations on your project? What do you use to measure voltage?

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

PiDi - the possible problem with your approach is that the signal could be zero for up to almost 40ms before the indicator would come on, instead of 20ms.

0 Kudos
Message 4 of 9
(3,041 Views)

I would use a VI to keep track of the time.  Luckily, LabVIEW has one Smiley Very Happy

 

This poles every 1ms.  The shift register is to keep track if the time has elapsed.  Without the shift register, we are not quick enough to see the time elapsed go high and then back to false.

Timer.png

Lewis Gear CLA
LabVIEW UAV

0 Kudos
Message 5 of 9
(3,036 Views)

One minor problem: 0.2s = 200ms, not 20ms.  Also, the "Not Equal to 0" function is a lot more compact and does exactly the same thing.  Of course, an analog signal is often close but not equal to 0, so the original poster might need a bit more logic.

0 Kudos
Message 6 of 9
(3,031 Views)

Thanks Lewis_G that is what I needed.  I'm still having a problem though.  I pull in the waveform, get the Y component, check that it is between 1 and -1 volt, but it is in an array and I need a single dbl to reset the Elapsed time function. 

 

I have attached an image of the VI.  For some reason when I pasted it into the message body it ran me over the character limit.

 

This is the error I'm getting.

 

"These cannot be wired together because their data types do not match.

The type of the source is 1D array of boolean (TRUE or FALSE)

THe type of the sink is boolean (TRUE or FALSE)"

 

Any ideas anyone?

0 Kudos
Message 7 of 9
(2,998 Views)

How many data points are in your waveform?  Where is the waveform coming from?  If you're only reading a single sample at a time then this is easy: just insert Index Array.  Another, possibly better, option is to replace the acquisition with a single point instead of a waveform.  If you're acquiring multiple data points at a time, then you may want to check each point in the waveform (depending on the requirements of your application).

 

The function you want is "In Range and Coerce" to check if the value is between -1 and +1.  There's never a need to do an equality comparison between a boolean and a constant - for example, equal to false is exactly the same as NOT.

 

You may want to read through some of the LabVIEW tutorials and getting started guides.

Message 8 of 9
(2,983 Views)

If you are dealing with a waveform (array of data), you could use the Or Array Elements function.

OR array elements.png

 

Kind Regards

Lewis Gear CLA
LabVIEW UAV

0 Kudos
Message 9 of 9
(2,976 Views)