Servo Motor Control Using SysTick Timer in Keil Software
Servo Motor Control Using SysTick Timer in Keil Software
DATE:05/02/2022
THEORY:
Servos are controlled by sending an electrical pulse of variable width, or pulse width
modulation (PWM), through the control wire. There is a minimum pulse, a maximum pulse,
and a repetition rate. A servo motor can usually only turn 90° in either direction for a total of
180° movement. The motor's neutral position is defined as the position where the servo has
the same amount of potential rotation in the both the clockwise or counter-clockwise
direction. The PWM sent to the motor determines position of the shaft, and based on the
duration of the pulse sent via the control wire; the rotor will turn to the desired position. The
servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will
determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn to
the 90° position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0°
position, and any longer than 1.5ms will turn the servo in a clockwise direction toward the
180° position.
unsigned long i;
void PortA_Init(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000001; //activating port clock
delay = SYSCTL_RCGC2_R;
GPIO_PORTA_AMSEL_R &= (0x00); //disable analog functionality
GPIO_PORTA_PCTL_R &= (0x00); //select GPIO functionality
GPIO_PORTA_DIR_R |= 0x20; //Enable PA5 as output
GPIO_PORTA_AFSEL_R &= (0x00); //Disable alternate function
GPIO_PORTA_DEN_R |= 0x20;
}
void SysInt(void) {
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}
void SysInt(void) {
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}
unsigned long i;
void PortA_Init(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000001; //activating port clock
delay = SYSCTL_RCGC2_R;
GPIO_PORTA_AMSEL_R &= (0x00); //disable analog functionality
GPIO_PORTA_PCTL_R &= (0x00); //select GPIO functionality
GPIO_PORTA_DIR_R |= 0x08; //Enable PA3 as output
GPIO_PORTA_AFSEL_R &= (0x00); //Disable alternate function
GPIO_PORTA_DEN_R |= 0x08;
}
void SysInt(void) {
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}
unsigned long i;
void PortB_Init(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000022; //activating port clock
delay = SYSCTL_RCGC2_R;
GPIO_PORTB_AMSEL_R &= (0x00); //disable analog functionality
GPIO_PORTB_PCTL_R &= (0x00); //select GPIO functionality
GPIO_PORTB_DIR_R |= 0x20; //Enable PB4 as output
GPIO_PORTB_AFSEL_R &= (0x00); //Disable alternate function
GPIO_PORTB_DEN_R |= 0x20;
}
void PortF_Init(void)
{
unsigned long volatile delay;
SYSCTL_RCGC2_R |= 0x020; // Port D clock
delay = SYSCTL_RCGC2_R; // wait 3-5 bus cycles
GPIO_PORTF_DIR_R |= 0x0E; // PD0 output
GPIO_PORTF_AFSEL_R &= ~0x0E; // not alternative
GPIO_PORTF_AMSEL_R &= ~0x0E; // no analog
GPIO_PORTF_PCTL_R &= ~0x000000F; // bits for PD0
GPIO_PORTF_DEN_R |= 0x0E; // enable PD0
}
void SysInt(void) {
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}
int main(void) {
PLL_Init();
PortB_Init();
PortF_Init();
SysInt();
while(1) {
for(i=56000;i<=184000;i+=10000) { //0 to 180 deg
GPIO_PORTB_DATA_R |=0x20;
GPIO_PORTF_DATA_R |=0x02;
SysLoad(i);
GPIO_PORTB_DATA_R &=~0x20;
GPIO_PORTF_DATA_R &=~0x02;
SysLoad(1600000-i);
}
GPIO_PORTB_DATA_R =0x00;
GPIO_PORTF_DATA_R =0x00;
SysLoad(16000000);
SysLoad(16000000);
SysLoad(8000000);
for(i=184000;i>=56000;i-=10000) { //180 to 0 deg
GPIO_PORTB_DATA_R |=0x20;
GPIO_PORTF_DATA_R |=0x08;
SysLoad(i);
GPIO_PORTB_DATA_R &=~0x20;
GPIO_PORTF_DATA_R &=~0x08;
SysLoad(1600000-i);
}
GPIO_PORTB_DATA_R =0x00;
GPIO_PORTF_DATA_R =0x00;
SysLoad(16000000);
}
}
INFERENCE:
Servos are used in radio-controlled airplanes to position control surfaces like elevators,
rudders, walking a robot, or operating grippers. Servo motors are small, have built-in control
circuitry and have good power for their size.
In food services and pharmaceuticals, the tools are designed to be used in harsher
environments, where the potential for corrosion is high due to being washed at high pressures
and temperatures repeatedly to maintain strict hygiene standards. Servos are also used in in-
line manufacturing, where high repetition yet precise work is necessary.
CONCLUSION:
Thus we learnt how to create specific delay and time interval to control servo motor in angles
0-90deg,0-135deg,0-180deg using systick timer in various ports.