LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HOW TO CREATE A COUNTER WHICH RESETS AFTER REACHING A THRESHOLD

Hello,

How can we create a counter which increments after certain milisecond and resets to zero after reaching the threshold, for example, an up counter which counts till 15 after 10ms and resets to zero after reaching 15.

 

Thanks & Regards,

Ravi

0 Kudos
Message 1 of 9
(2,887 Views)

This is a good opportunity to look into shift registers, if you haven't done so before.

 

http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/shift_registers_concepts/

 

SNIPPET!.png

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

Hi ravi,

 

using Modulo you can easily reset to zero: x:=x MOD threshold…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 9
(2,880 Views)

Hello Potterton,

Thanks for your reply. It's indeed a good approach to create a counter. I want each value of counter continuously from 0 to 15 so that it can be used further ahead in the program. If I place a tunnel, it would only display the last value of the count when the while loop has finished execution. What is the alternative for it?

 

Thanks & Regards

Ravi

0 Kudos
Message 4 of 9
(2,828 Views)

@ravi0591 wrote:

Hello Potterton,

Thanks for your reply. It's indeed a good approach to create a counter. I want each value of counter continuously from 0 to 15 so that it can be used further ahead in the program. If I place a tunnel, it would only display the last value of the count when the while loop has finished execution. What is the alternative for it?


You probably need to place the "further up" code also inside this while loop.

Maybe you could use a state machine where one of the states does the incrementing and other states do the "further up" code.

 

Please give us more details on your code architecture so we can give more precise advice.

0 Kudos
Message 5 of 9
(2,813 Views)

Hello Altenbach,

I solved my problem by using the concept of local variable. Thank you anyways for giving your valuable time on this.

 

Thanks & Regards,

Ravi

0 Kudos
Message 6 of 9
(2,793 Views)

@ravi0591 wrote:

Hello Altenbach,

I solved my problem by using the concept of local variable. Thank you anyways for giving your valuable time on this.

 

Thanks & Regards,

Ravi


Smiley Surprised why not use the shift register?

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

Hello Muks,

I used shift register for generating the counter as suggested by Mr. Potterton earlier. But later,  I wanted to use the value of that counter ahead in my program, so I used local variable for this Smiley Happy

 

Thanks,

Ravi

0 Kudos
Message 8 of 9
(2,777 Views)

That is generally a bad idea and just screams bad architecture in which you will run into major problems.  You are left wide open to a possibly really bad race condition.

 

What exactly are you trying to do with this program.  We can likely find you a better way that actually uses data flow.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(2,767 Views)