04-20-2015 06:37 AM
Hi !
I have a timed loop with a cadence set by user . And when the loop is running, I can not push any button of my GUI to stop this....
I have to wait until error or I stop the run.
I can't put the diagram it's too big and I think I haven't the right but do you have some ideas ?
Ask me for more details .
Thanks
Solved! Go to Solution.
04-20-2015 07:46 AM
How long is your loop supposed to wait for? If it is more than a few hundred ms, I would set up a state machine where you can check for user interactions and check to see how much time has expired before performing your repeated action.
It would help us if you post some code so we can see exactly what you are trying to accomplish.
04-20-2015 08:27 AM
The notion of a timed loop is that not only does it run every N "ticks" (a tick is often a millisecond, but on an RT system, can be other things), it also sits idle until it's time to run again. If your loop time is, say, 20 seconds, and it only takes, say, 10 milliseconds to do whatever you need to do in the loop, this means that for 19.98 seconds, your Timed Loop is unresponsive and will not respond to a Stop command.
If this is a problem, one way to handle this is to have the loop run on a shorter clock cycle. In the previous example, you could set the Timed Loop for 100 msec, and say "Execute this code every 200th time through the loop, i.e. every 20 seconds, otherwise do nothing". Now a Stop command will register within 100 msec, yet your Timed Loop will still execute its code at the desired rate, with almost no "lost time" (the time to "ignore this tick" is undoubtedly measured in small fractions of a microsecond).
Bob Schor
04-22-2015 01:24 PM - edited 04-22-2015 01:28 PM
Thank you, I understand the problem and I think it is it .
How to say " execute each 200th otherwise do nothing " ?
I have tried with an " If Structure" which depends on "i" and I compare for exemple 200 to "i" . Then I add 200 to compare for the next time. I set 10,100,500ms for Timed Loop but it doesn't work .
The time I want is a few seconds ( 3,5 ) from 10,15 s
04-22-2015 06:29 PM - edited 04-22-2015 06:30 PM
Do not use the i. That can open up some cans of worms. Instead, keep a count in the shift register. Each iteration you increment and then use Quotient & Remainder to divide by your number of desired cycles to run. Keep the remainder in the shift register and compare it to 0. When the remainder is 0, you can do your operation.

04-22-2015 06:46 PM
crossrulz wrote:
Do not use the i. That can open up some cans of worms. Instead, keep a count in the shift register. Each iteration you increment and then use Quotient & Remainder to divide by your number of desired cycles to run. Keep the remainder in the shift register and compare it to 0. When the remainder is 0, you can do your operation.
This may be getting a little bit off topic, but what are you referring to when you mean using the i will open a can of worms?
04-22-2015 06:50 PM
@ogk.nz wrote:
@crossrulz wrote:
Do not use the i. That can open up some cans of worms. Instead, keep a count in the shift register. Each iteration you increment and then use Quotient & Remainder to divide by your number of desired cycles to run. Keep the remainder in the shift register and compare it to 0. When the remainder is 0, you can do your operation.
This may be getting a little bit off topic, but what are you referring to when you mean using the i will open a can of worms?
Well, in a Windows system you won't run into any problems unless you run for a long time. In FPGA and RT, it becomes a huge problem. So the i terminal is an I32. So what does it do when it reaches the maximum value? It does not roll over. It sticks at the max value. So if you are trying to do math on the i, after so long your math will just stick. So I learned to just keep my own count that I can control when it resets and what not.
04-23-2015 03:47 PM
So I did like you .
I attached the piece of code. The Timed loop is just in an event structure and I set 10 ms or 100 ms .
The program is running correctly (with this Timed loop of 10ms/100 ms) as the beginning but I still can't push any button or change tabs during the loop .
04-23-2015 06:26 PM
bejard wrote: The Timed loop is just in an event structure and I set 10 ms or 100 ms .
The program is running correctly (with this Timed loop of 10ms/100 ms) as the beginning but I still can't push any button or change tabs during the loop .
You should not have long processes inside of an event case. What is supposed to stop your timed loop?
I think you have the "Lock front panel until event case completes" option turned on. This will not allow you to press anything until everything in that event case (including the timed loop) completes.
In my experience, using a timed loop in a Windows system is a complete waste and often adds more overhead and issues. Instead, I really think you need to change over to use a State Machine. When the button is pressed, you just tell your state machine to go into the state the runs some of the code inside of your timed loop. You can use the state with the event structure to time your loop. So you can go back and forth from your event structure state to your processing loop. Just set the timeout on the event structure to whatever loop rate you actually want.
04-23-2015 11:18 PM