3 Motion Control

The basic motion control logic should be timer interrupt driven. This logic is responsible to execute a motion profile based on displacement (distance), top velocity (speed), acceleration and deceleration. This module does not discuss this logic. Rather, this module assumes there is an interface to the basic motion control logic:

Because the motion control logic is interrupt driven, there is not much that relates to threads. The only precaution is that any access of variables used in the ISR must be “protected”. This is because an interrupt can occur right in the middle of an access to a structure shared with the ISR. To ensure synchronzation with an ISR, interrupt should be disabled before the access, and restored after. For the AVR, the easiest way to do this is as follows:

char savedSREG = SREG;  
asm("cli");  
// now access a variable shared with the ISR  
SREG = savedSREG; // restores interrupt flag