04-21-2017 07:03 PM - edited 04-21-2017 07:05 PM
Hello, NI community. First time poster here. I have a question that I hope has a simple answer. I have a while loop, in which I'm tallying the number of "hours" that the loop has been running for. I decided that 12 iterations = 1 "hour". I have created a shift register that is tallying every 12th iteration as an hour. Inside the while loop, I have a case structure that is toggled by a boolean push button. My question is this: how can I track the number of "hours" that the button is in the "On" state?
I can't use an event structure because eventually I will have 10-12 similar case structure Sub VI's running simultaneously in this code, each polling how long each Sub VI is running. Additionally, an event structure would pause the tallying of hours in the shift register, and therefore when the button is turned off, it wouldn't record the right amount.
The file is attached. Help is very much appreciated!
P.S. This is not my main code, this is just a small program illustrating the problem I am having. In this small portion of code, the number of hours keeps going as long as you're running the code. In reality, I have it restarting after 24 tallies.
04-21-2017 07:34 PM
Don't use the i terminal in the loop. That increments every iteration whether you want it to or not.
Use the increment function in a case structure on the value you are storing in the shift register. Increment if true. Don't if false. Perhaps you want it to reset to 0 if false.
04-21-2017 07:39 PM
Thanks for the reply.
I'm using the loop iteration count for two reasons.
1) Some of the applications might only run for a fraction of an "hour", which is why I'm not just considering one iteration per hour.
2) All of the Sub VI's will basically be performing the same function: tracking how long they are turned on. They're all referenced to the main loop, because the main loop models a full day, and I'm tracking how long each sub VI is on throughout the "day".
04-21-2017 09:08 PM - edited 04-21-2017 09:09 PM
@engrstudent1 wrote:
Thanks for the reply.
I'm using the loop iteration count for two reasons.
1) Some of the applications might only run for a fraction of an "hour", which is why I'm not just considering one iteration per hour.
I don't understand how that comment has anything to do with what I told you. Right now you are trying to tell time by counting loop iterations, Some of which don't apply when your device. Loop iterations will count by 1 every iteration. I'm tell you to make your own counter that you increment by 1 yourself only when you need to, like when your device is on.
2) All of the Sub VI's will basically be performing the same function: tracking how long they are turned on. They're all referenced to the main loop, because the main loop models a full day, and I'm tracking how long each sub VI is on throughout the "day".
So you don't reset the counter to 0 when it turns off, you just send the previous value to the shift register.
