Exp 11
Exp 11
Hardware tool:
MSP430G2 launchpad
Servo (SG90) Motor
Jumper Wires
Abstract:
A servo consists of a Motor (DC or AC), a potentiometer, gear assembly, and a
controlling circuit. First of all, we use gear assembly to reduce RPM and to increase
torque of the motor. Servo motor is controlled by PWM (Pulse with Modulation)
which is provided by the control wires. There is a minimum pulse, a maximum pulse
and a repetition rate. Servo motor can turn 90 degree from either direction form its
neutral 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, such as if pulse is shorter
than 1.5ms shaft moves to 0° and if it is longer than 1.5ms than it will turn the servo to
180°.
Used as actuators in many robots like Biped Robot, Hexapod, robotic arm etc..
Commonly used for steering system in RC toys.
Robots where position control is required without feedback.
Less weight hence used in multi DOF robots like humanoid robots.
Block diagram:
Algorithm:
1. Start
2. Stop watchdog timer
3. Calibrate BCSCTL1 (Basic clock system control) register to 1Mhz
4. Calibrate DCOCTL (Digital Control Oscillator) register to 1Mhz
5. Setting sets the P1DIR to 01000001.
6. set the P1SEL as 1 for BIT6
7. In an infinite loop:
Start timer with 20ms period
for loop which goes from 350 to 2350 with increment of 1.
TACCR1 = i
TA0.1 in Reset/Set output mode
TACTL = TASSEL_2|MC_1;
Wait for 1.97 * 10^-5 sec
Wait for 1.94 * 10^-3 sec
Source code:
#include <msp430.h>
int i;
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
BCSCTL1= CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
//PWM period
P1DIR |= BIT6;
P1SEL |= BIT6; //selection for timer setting
while(1) {
TACCR0 = 20000; //PWM period
for (i=350; i<=2350; i++) {
TACCR1 = i;
TACCTL1 = OUTMOD_7; //CCR1 selection reset-set
TACTL = TASSEL_2|MC_1; //SMCLK submain clock,upmode
__delay_cycles(1000);
}
__delay_cycles(1000000);
}}
Procedure:
1. Open Code Composer Studio and create a new project
2. Write the C program and save it with appropriate name
3. Build the program
4. Debug the program
Conclusion: We have learned the working principle of Servo Motor and saw it’s
implementation with Msp430 using Code Composer Studio Software. We wrote the code for
servo for rotating 180* and resetting to its position in smooth manner. We also rotated the
servo for other angles. We discussed various other applications of this project in other fields.