Hi 🙂 My program runs for a given time and writes data to a file. After the time has been reached the program goes into a "pause" loop, where nothing happens, and then begins running again. I want to be able to decide have many times it runs the program. I know I can use a for loop, but I want to try to use some sort of counter as you can see in the attachment file below. After the counter has reached the given value, then the entire program stops.
Solved! Go to Solution.
Why don't you do what you are already showing with a shift register, increment, and comparison in the while loop?
(You should make those values integers rather than double since you are just counting. You can run into problems when when comparing floating point numbers (doubles) for equality.)
Your counter belongs in the state machine loop. You might want to add a state to increment and check to see if you are complete.
Hi! Thank you for the tips. I still can't manage to figure out the solution. I added the loop counter as a new state. When we get to "Count", the value should begin at 0 and add 1 for each time it executes. Right now it adds the same value as my "Number of intervals" control is set to. I want it to return back to "Collect data" after adding "1".
There is no reason to have the loop inside of the "Count" case. Your "loop count" should be a shift register on the main loop.