LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a simple counting program?

I am trying to write a subVI that will allow me to count the number of times a specific event occurs so that I may trigger a measurement. In the program, I want to count the number of times that a generated number less than 0.80 (for example) occurs. So each time a number < 0.80 occurs, I want to count it. However, here is the twist, I want to trigger measuring only when the counter has counted the < 0.80 condition ten times (for example) one after the other, i.e. there must not be a > 0.80 reading in ten consecutive readings. I�ve uploaded my VI (Labview version 6.0) and would appreciate any help I can get.
0 Kudos
Message 1 of 11
(4,068 Views)
Try this. Note that if you plan to use this VI in more than one place you will need to make it reentrant.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 11
(4,068 Views)
Try using shift registers. They allow you to pass values from
one loop iteration to the next. Then for each value less than 0.8
increment a counter. Reset the counter if a value greater than 0.8
occurs. Trigger when the counter gets to 10.

(Is this homework?)

Les
0 Kudos
Message 3 of 11
(4,068 Views)
Hello Mike,

Your program captures exactly what it is I want to do. I have one more question, what do you mean by making it reentrant?

Thanks again!
0 Kudos
Message 4 of 11
(4,068 Views)
Hi Les,

Thanks for your comments. I am new to Labview and realize that I do need to use shift registers but I am not experienced enough to do so yet. Mike's program captures exactly what I need.
0 Kudos
Message 5 of 11
(3,895 Views)
Reentrant means that each copy of the VI that is loaded into memory runs in its own memory space. That feature is important because the shift register in the code I sent you is uninitialized. That means that the diagram isn't giving it a value to start with. Instead it utilizes the value stored in it the last time it ran--in essence the shift register becomes a memory that stores data.

In the code I sent you, you want the code to be reentrant so that if you use it in multiple places, the data from the various places it's called won't interfere with one another.

To make a VI reentrant, right-click on the icon and select "VI Properties...". In the resulting dialog box select "Execution" from the Catagories popup menu and check the box title
d: "Reentrant Execution".

For more information on reentrancy, check out this forum, there was a recent thread about it.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 11
(4,068 Views)
Hi Mike,

I've been playing some more with your program and I noticed that even though the counting condition is met, the counter keeps on incrementing. Is there a way to reset the shift register value to zero once the counting condition has been met? I've been trying to place a Case structure within the While loop to do this but to no avail. Can you help me once again with this? Thanks.
0 Kudos
Message 7 of 11
(4,068 Views)
Here you go...

I have sent you two variations. The first routine is like the first but generates a true output for one iteration only, every 10 times it's run with the input value below 0.8. If this is put into a loop the effect will be that it will generate a pulse every 10 loops--which is literally what you asked for, but it seems like it's probibly not what you really need.

The second generates a true output for one iteration after it's been run 10 times with the input value less than 0.8. The counter value never really resets, but it doesn't matter because the output comparison is looking for the count to be exactly 10.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Download All
0 Kudos
Message 8 of 11
(4,068 Views)
Hi Mike,

Sorry for the delay in getting back to you. The new VI you sent works much better (true ouput every 10 iterations.vi). Incidentally, I finally got the case structure to work, however your solution is very quick and to the point. Thanks again!
0 Kudos
Message 9 of 11
(4,068 Views)
I have a similar problem with counting. The third example (condition1back3.vi) is quite near to what I'm looking for. But I need to change the limit (0.8 in the example) everytime it is overstept. So that the next limit is 10 higher than the last one. If I do so, Labview complains about the circle I created.
I have an increasing rpm signal and the aim is to save some data every 10 rpm.
Thank you for your affords.

Nico
0 Kudos
Message 10 of 11
(4,068 Views)