0% found this document useful (0 votes)
116 views10 pages

Servo Motor Control Using SysTick Timer in Keil Software

The document describes using a SysTick timer to control a servo motor by creating specific time delays. It explains that servos are controlled through pulse width modulation where the pulse length determines the angle of rotation. Sample code is provided to rotate a servo from 0 to 90 degrees, 0 to 135 degrees, and 0 to 180 degrees using different GPIO ports and time delays set by the SysTick timer. The conclusion states that creating precise time delays with the SysTick timer allows controlling the servo motor's angle of rotation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views10 pages

Servo Motor Control Using SysTick Timer in Keil Software

The document describes using a SysTick timer to control a servo motor by creating specific time delays. It explains that servos are controlled through pulse width modulation where the pulse length determines the angle of rotation. Sample code is provided to rotate a servo from 0 to 90 degrees, 0 to 135 degrees, and 0 to 180 degrees using different GPIO ports and time delays set by the SysTick timer. The conclusion states that creating precise time delays with the SysTick timer allows controlling the servo motor's angle of rotation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EXP 3: SERVO MOTOR CONTROL

USING SYSTICK TIMER

DATE:05/02/2022

NAME: KOWSHIK KUMAR K.

ROLL NO: CED19I004


AIM:
To create specific time delay and time interval to control the servo motor
using SysTick timer.

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.

CODE (SAMPLE PROGRAM):


#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"

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 SysLoad(unsigned long period) {


NVIC_ST_RELOAD_R = period-1;
NVIC_ST_CURRENT_R = 0;
while((NVIC_ST_CTRL_R&0x00010000)==0) {
}
}
int main(void) {
PLL_Init();
PortA_Init();
SysInt();
while(1) {
for(i=56000;i<=120000;i+=10000) { //0 to 90 deg
GPIO_PORTA_DATA_R |=0x20;
SysLoad(i);
GPIO_PORTA_DATA_R &=~0x20;
SysLoad(1600000-i);
}
for(i=120000;i>=56000;i-=10000) { //90 to 0 deg
GPIO_PORTA_DATA_R |=0x20;
SysLoad(i);
GPIO_PORTA_DATA_R &=~0x20;
SysLoad(1600000-i);
}
}
}
OUTPUT (SAMPLE PROGRAM):

CODE (EXAMPLE PROGRAM):


#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"
unsigned long i;
void PortB_Init(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000002; //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 |= 0x10; //Enable PB4 as output
GPIO_PORTB_AFSEL_R &= (0x00); //Disable alternate function
GPIO_PORTB_DEN_R |= 0x10;
}

void SysInt(void) {
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}

void SysLoad(unsigned long period) {


NVIC_ST_RELOAD_R = period-1;
NVIC_ST_CURRENT_R = 0;
while((NVIC_ST_CTRL_R&0x00010000)==0) {
}
}
int main(void) {
PLL_Init();
PortB_Init();
SysInt();
while(1) {
for(i=56000;i<=184000;i+=30000) { //0 to 180 deg
GPIO_PORTB_DATA_R |=0x10;
SysLoad(i);
GPIO_PORTB_DATA_R &=~0x10;
SysLoad(1600000-i);
}
for(i=184000;i>=56000;i-=30000) { //180 to 0 deg
GPIO_PORTB_DATA_R |=0x10;
SysLoad(i);
GPIO_PORTB_DATA_R &=~0x10;
SysLoad(1600000-i);
}
}
}

OUTPUT (EXAMPLE PROGRAM):


CODE (ASSIGNMENT 1 PROGRAM):
#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"

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;
}

void SysLoad(unsigned long period) {


NVIC_ST_RELOAD_R = period-1;
NVIC_ST_CURRENT_R = 0;
while((NVIC_ST_CTRL_R&0x00010000)==0) {
}
}
int main(void) {
PLL_Init();
PortA_Init();
SysInt();
while(1) {
for(i=56000;i<=152000;i+=20000) { //0 to 135 deg
GPIO_PORTA_DATA_R |=0x08;
SysLoad(i);
GPIO_PORTA_DATA_R &=~0x08;
SysLoad(1600000-i);
}
for(i=152000;i>=56000;i-=20000) { //135 to 0 deg
GPIO_PORTA_DATA_R |=0x08;
SysLoad(i);
GPIO_PORTA_DATA_R &=~0x08;
SysLoad(1600000-i);
}
}
}

OUTPUT (ASSIGNMENT 1 PROGRAM):

CODE (ASSIGNMENT 2 PROGRAM):


#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"

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;
}

void SysLoad(unsigned long period) {


NVIC_ST_RELOAD_R = period-1;
NVIC_ST_CURRENT_R = 0;
while((NVIC_ST_CTRL_R&0x00010000)==0) {
}
}

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);
}
}

OUTPUT (ASSIGNMENT 2 PROGRAM):

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.

You might also like