Sunteți pe pagina 1din 12

A

PROJECT REPORT

ON

RC SERVO MOTOR CONTROL

Electronics & Telecommunication

SUBMITTED BY

Name of the student PRN


SAMEER KHAN 15070121380
OMKAR JADAV 15070121366
P. DINESH KRISHNA 15070121367

Under the Guidance of

Prof. Shripad Deshpande


SYMBIOSIS INSTITUTE OF TECHNOLOGY, PUNE – 412115

Introduction:
Servo motors (or servos) are self-contained electric devices that rotate
or push parts of a machine with great precision. Servos are found in
many places: from toys to home electronics to cars and airplanes. If you
have a radio-controlled model car, airplane, or helicopter, you are using
at least a few servos. In a model car or aircraft, servos move levers back
and forth to control steering or adjust wing surfaces. By rotating a shaft
connected to the engine throttle, a servo regulates the speed of a fuel-
powered car or aircraft. Servos also appear behind the scenes in devices
we use every day. Electronic devices such as DVD and Blu-ray
Disc players use servos to extend or retract the disc trays. In 21st-
century automobiles, servos manage the car's speed. The gas pedal,
similar to the volume control on a radio, sends an electrical signal that
tells the car's computer how far down it is pressed. The car's computer
calculates that information and other data from other sensors and sends a
signal to the servo attached to the throttle to adjust the engine speed.
Commercial aircraft use servos and a related hydraulic technology to
push and pull just about everything in the plane.

RC Servos are small, cheap, mass-produced servomotors or


other actuators used for Radio Control and small-scale robotics. Radio
control servos are connected through a standard three-wire connection:
two wires for a DC power supply and one for control, carrying a PWM
(pulse-width modulation) signal. Each servo has a separate connection
and PWM signal from the radio control receiver. This signal is easily
generated by simple electronics, or by microcontrollers such as
the Arduino. This, together with their low-cost, has led to their wide
adoption for robotics and physical computing.
Project Description:
In this project, we used PWM1 output from Pin P0.0 to control a RC
Servo Motor. We will also be using 4 tactile switches to bring the Servo
at 4 different positions. P0.1, P0.2, P0.3, P0.4 will be used to take the
input. One end of the tactile switches will be connected to each of these
Pins and other end will be connected to ground. Here we'll also require
external 5V-6V source to drive the servo. Servos can work with 3.3v
voltage levels for input PWM signal, hence we just need to connect the
MCU PWM Output to Servo PWM Input wire. The setup is as shown in
the schematic below:

When the user will press P0.1 the Pulse width will be 1ms, and similarly
when the user presses P0.2, P0.3, P0.4 the Pulse Width will change to
1.25ms, 1.5ms and 1.75ms respectively and hence Servo will change its
position correspondingly.
ARM PERIPHERALS USED
 Pulse width modulation (PWM) is a powerful technique for
controlling analog circuits with a processor's digital outputs.
PWM is employed in a wide variety of applications, ranging
from measurement and communications to power control and
conversion.
A period of a pulse consists of an ON cycle (HIGH) and
an OFF cycle (LOW). The fraction for which the signal is ON over
a period is known as duty cycle.

Interfacing PWM with LPC2148


Generate a PWM in LPC2148 Development Board at a
particular frequency. Pulse Width Modulation is a technique for
getting analog results with digital means.
Digital control is used to create a square wave, a signal
switched between on and off. This on-off pattern can simulate
voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus
the time that the signal spends off. The duration of "on time" is
called the pulse width. To get varying analog values, you
change, or modulate, that pulse width.
LPC2148 supports 2 types of PWM:

1) Single Edge PWM – Pulse starts with new Period i.e. pulse is always
at the beginning.
2) Double Edge PWM – Pulse can be anywhere within the Period
Registers Description of PWM

PWMTCR PWM Timer Control Register– PWMTCR is used to control


the timer counter functions. The Timer Counter can be
disable or reset through the PWMTCR

PWMPR PWM Prescale Register– The PWMTC (PWM Timer


Counter) is incremented every PWMPR+1 cycles of PCLK.

PWMMR0- PWM Match Register 0- PWM Match Register 6–


PWMMR6 PWMMR0-6 can be enabled through PWMMCR to reset the
PWMTC, stop both the PWMTC and PWMPC, and/or
generate an interrupt when it matches the PWMTC. In
addition, a match between PWMMR0-PWMMR6 and the
PWMTC sets all PWM outputs that are single edge mode and
sets PWM1 if it is in double-edge mode.

PWMMCR PWM Match Control Register– The PWMMCR is used to


control if an interrupt is generated and if the PWMTC is
reset when match occurs.

PWMIR PWM Interrupt Register– The PWMIR can be written to


clear interrupt. The PWMIR can be read to identify which of
the possible interrupt sources are pending.

PWMLER PWM Latch Enable Register– Enables use of new PWM


Match values.

PWMPCR PWM Control Register– Enables PWM outputs and selects


PWM channel types as either single edge or double edge
controlled.
 Phase Lock Loop (PLL) is used to generate system clock from
between 10 MHz to 25 Mhz. PLL may multiply frequency to range
from 10 MHz to 60 MHz and 48 MHz for USB if used. PLL uses
frequency multiplier which can be in a range from 1 to 32, in real
world situation this value should not be higher than 6 due to upper
frequency limit. PLL generator allows running ARM at high speed
with low frequency oscillator connected. Also, this minimizes
EMC emission as frequency is multiplied inside ARM Chip. PLL
allows changing frequency dynamically. In LPC2148
microcontrollers there are two PLLs which provide programmable
frequencies to the CPU and USB System.
The Peripheral Clock i.e. PCLK is derived from CPU Clock i.e.
CCLK. The APB Divider decides the operating frequency of
PCLK. The input to APB Divider is CCLK and output is PCLK.
By Default, PCLK runs at 1/4th the speed of CCLK. To control
APB Divider, we have a register called VPBDIV. The value in
VPBDIV controls the division of CCLK to generate PCLK as
shown below:

VPBDIV=0x00 APB bus clock (PCLK) is one fourth of the processor clock (CCLK)

VPBDIV=0x01 APB bus clock (PCLK) is the same as the processor clock (CCLK)

VPBDIV=0x02 APB bus clock (PCLK) is one half of the processor clock (CCLK)

Reserved. If this value is written to the APBDIV register, it has no


VPBDIV=0x03
effect (the previous setting is retained)
CODE:
#include <lpc214x.h>
#define PLOCK 0x00000400
#define PWMPRESCALE 60 //60 PCLK cycles to increment TC by 1 i.e 1 Micro-second
void initPWM(void);
void initClocks(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);
int main(void)
{
initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz
initPWM(); //Initialize PWM
while(1)
{
if( !((IO0PIN) & (1<<1)) ) // Check P0.1
{
PWMMR1 = 1000;
PWMLER = (1<<1); //Update Latch Enable bit for PWMMR1
}
else if( !((IO0PIN) & (1<<2)) ) // Check P0.2
{
PWMMR1 = 1250;
PWMLER = (1<<1);
}
else if( !((IO0PIN) & (1<<3)) ) // Check P0.3
{
PWMMR1 = 1500;
PWMLER = (1<<1);
}
else if( !((IO0PIN) & (1<<4)) ) // Check P0.4
{
PWMMR1 = 1750;
PWMLER = (1<<1);
}
}
}
void initPWM(void)
{
PINSEL0 = (1<<1); // Select PWM1 output for Pin0.0
PWMPCR = 0x0; //Select Single Edge PWM - by default its single Edged so this line can
be removed
PWMPR = PWMPRESCALE-1; // 1 micro-second resolution
PWMMR0 = 20000; // 20ms period duration
PWMMR1 = 1000; // 1ms - pulse duration i.e width (Brigtness level)
PWMMCR = (1<<1); // Reset PWMTC on PWMMR0 match
PWMLER = (1<<1) | (1<<0); // update MR0 and MR1
PWMPCR = (1<<9); // enable PWM output
PWMTCR = (1<<1) ; //Reset PWM TC & PR
PWMTCR = (1<<0) | (1<<3); // enable counters and PWM Mode
}
void initClocks(void)
{
setupPLL0();
feedSeq(); //sequence for locking PLL to desired freq.
connectPLL0();
feedSeq(); //sequence for connecting the PLL as system clock
VPBDIV = 0x01; // PCLK is same as CCLK i.e 60Mhz
}

void setupPLL0(void)
{
PLL0CON = 0x01; // PPLE=1 & PPLC=0 so it will be enabled
// but not connected after FEED sequence
PLL0CFG = 0x24; // set the multipler to 5 (i.e actually 4)
// i.e 12x5 = 60 Mhz (M - 1 = 4)!!!
// Set P=2 since we want FCCO in range!!!
}
void feedSeq(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}
void connectPLL0(void)
{
// check whether PLL has locked on to the desired freq by reading the lock bit
// in the PPL0STAT register
while( !( PLL0STAT & PLOCK ));
// now enable(again) and connect
PLL0CON = 0x03;
}
OUTPUT:
Conclusion:

S-ar putea să vă placă și