06-30-2014 05:26 AM
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
06-30-2014 05:36 AM
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/
06-30-2014 05:37 AM
06-30-2014 11:57 PM
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
07-01-2014 12:52 AM - edited 07-01-2014 12:54 AM
@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.
07-01-2014 04:24 AM
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
07-01-2014 05:28 AM
@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
why not use the shift register?
07-01-2014 05:31 AM
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
Thanks,
Ravi
07-01-2014 06:48 AM
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.