KMotion/KFlop Preemptive Multitasking

KMotion/KFlop uses a simple method of preemptive multitasking.  User Programs (Threads) and the System Thread context switch every Servo Interrupt and sequence in a round robin order.

 

The above example shows a case where two User Threads are currently active. 

 

The C function WaitNextTimeSlice() can be used to wait until the next context switch occurs and return immediately at the beginning of the next time slice.  This can assure that the User Program can execute for a few microseconds without being interrupted and at a very stable rate (with a few microseconds of jitter).

 

The time period between executions of each user thread is a function of the number of active User Threads:

 

Period = (# User Threads + 1) * TIMEBASE