# Synchronizing to controller cycle

**URL:** <https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922>\
**Category:** RAPID Programming\
**Tags:** controller-cycle, wait, syncronization\
**Created:** [January 18, 2021, 1:49pm UTC](https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922 "2021-01-18T13:49:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkatliar](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mkatliar](https://tech-community.robotics.abb.com/u/mkatliar)\
**Post date:** [January 18, 2021, 1:49pm UTC](https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922/1 "2021-01-18T13:49:02Z")

</div>

Dear colleagues,  
I want some code to be executed on each controller cycle. This is what I have in mind:

MODULE SomeModule  
PROC MyProc()  
WHILE TRUE DO  
! do something important  
DoSomething;

! here I want to wait until the next controller cycle, how can I do that?  
WaitUntilNextControllerCycle;  
ENDWHILE  
ENDPROC  
ENDMODULE

The thing is that I can’t find a way in RAPID to wait for the next controller cycle; does it exist?  
I could use WaitTime, but then a) it is not synchronized to the controller cycle; b) the time of the WHILE cycle will be equal to the wait interval + the execution time of DoSomething, but I want DoSomething to be executed at regular intervals.

What would you suggest?

---

<div class="post-metadata">

**Author:** ![VictorAx](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@VictorAx](https://tech-community.robotics.abb.com/u/VictorAx)\
**Post date:** [January 18, 2021, 3:10pm UTC](https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922/2 "2021-01-18T15:10:04Z")

</div>

I don’t really understand your question, do you want this to be used as a continiously running proc while the robot is doing something else?

If so, is this meant a second task?

---

<div class="post-metadata">

**Author:** ![mkatliar](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mkatliar](https://tech-community.robotics.abb.com/u/mkatliar)\
**Post date:** [January 19, 2021, 10:45am UTC](https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922/3 "2021-01-19T10:45:52Z")

</div>

> [@VictorAx](#):
>
> I don’t really understand your question, do you want this to be used as a continiously running proc while the robot is doing something else?
> 
> If so, is this meant a second task?

Yes you are correct – this is supposed to be run in a separate “monitoring” task. The second task is the motion task.

---

<div class="post-metadata">

**Author:** ![VictorAx](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@VictorAx](https://tech-community.robotics.abb.com/u/VictorAx)\
**Post date:** [January 19, 2021, 11:39am UTC](https://tech-community.robotics.abb.com/t/synchronizing-to-controller-cycle/9922/4 "2021-01-19T11:39:06Z")

</div>

Then you could do something like this;

PROC main()

Set StartMonitor; !StartMonitor is configured as a digital output  
WaitUntil StartMonitor = 0;  
DoSomething;

ENDPROC

PROC Monitor();

WaitUntil StartMonitor = 1;  
Reset StartMonitor;

DoSomethingElse;  
ENDPROC
