In our previous tutorial, we have interfaced stepper motor with ARM7-LPC2148. In this tutorial, we will control Servo Motor with ARM7-LPC2148. Servo motor has low power consumption advantage over stepper motor. A servo motor stops its power consumption when the desired position is reached but the stepper motor continuous to consume power to lock up the shaft in desired position. Servo motors are mostly used in Robotics Projects because of their accuracy and easy handling.

In this tutorial we will learn about Servo Motor and How to interface Servo with ARM7-LPC2148. A potentiometer is also interfaced to vary the position of the servo motor’s shaft, and a LCD to display the angle value.

Servo Motor

A Servo Motor is a combination of DC motor, position control system and gears. Servo motor’s rotation is controlled by applying a PWM signal to it, width of the PWM signal decides the rotation angle and direction of the motor. Here we will be using SG90 Servo Motor in this tutorial, it is one of the popular and cheapest one. SG90 is a 180 degree servo. So with this servo we can position the axis from 0-180 degrees:

Operating Voltage: +5V

Gear Type: Plastic

Rotation Angle: 0 to 180 deg

Weight: 9gm

Torque: 2.5kg/cm

Before we can start programming for the Servo motor we should know what type of signal is to be sent for controlling the Servo motor. We should program the MCU to send PWM signals to the signal wire of the Servo motor. There is a control circuitry inside the servo motor which reads the duty cycle of the PWM signal and positions the servo motors shaft in the respective place as shown in the picture below

For every 20 milliseconds Servo motor checks the pulse. So, adjust the pulse width of the signal to rotate the motor’s shaft.

1 ms (1 millisecond) pulse width for rotation of servo to 0 degree

1.5ms pulse width for rotation to 90 degree (neutral position)

2 ms pulse width for rotation of servo to 180 degree.

Before Connecting Servo to ARM7-LPC2148, you can test your servo with the help of this Servo Motor Tester Circuit. Also check how a servo motor can be interfaced with other Microcontrollers:

Controlling Servo Motor using LPC2148 PWM & ADC

A Servo Motor can be controlled by LPC2148 using PWM. By providing PWM signal to SERVO’S PWM pin with a period of 20ms and frequency of 50Hz we can position the shaft of servo motor around 180 degrees (-90 to +90).

A Potentiometer is used to vary the duty cycle of PWM signal and rotate the servo motor’s shaft, this method is implemented by using the ADC module in LPC2148. So we need both PWM and ADC concepts to be implemented in this tutorial. So kindly refer our previous tutorials to learn PWM and ADC in ARM7-LPC2148.

1. A voltage regulator of 3.3V is used here to provide analog input value to the ADC pin (P0.28) of LPC2148. As we are using 5V power we need to regulate voltage with voltage regulator of 3.3V.

2. A Potentiometer is used to vary voltage between (0V to 3.3V) to provide analog input (ADC) to LPC2148 pin P0.28

3. The pin P0.1 of LPC2148 provides PWM output to the servo motor to control the position of the motor.

4. According to the analog input (ADC) value the position of the servo motor changes from (0 to 180 degree) through PWM output pin at P0.1 of LPC2148.

Programming ARM7-LPC2148 for Servo Motor Control

To Program ARM7-LPC2148 we need keil uVision & Flash Magic tool. We are using USB Cable to program ARM7 Stick via micro USB port. We write code using Keil and create a hex file and then the HEX file is flashed to ARM7 stick using Flash Magic. To know more about installing keil uVision and Flash Magic and how to use them follow the link Getting Started With ARM7 LPC2148 Microcontroller and Program it using Keil uVision.

Steps involved in configuring LPC2148 for PWM & ADC to control the Servo Motor

Step 2:- Next thing is to configure the PLL for clock generation as it sets the system clock and peripheral clock of LPC2148 as per programmers need. The maximum clock frequency for LPC2148 is 60Mhz. Following lines are used to configure PLL clock generation.

Step 9:- Now we need to get the potentiometer values for setting duty cycle of PWM from ADC pin P0.28. So, we use ADC module in LPC2148 for converting potentiometers analog input (0 to 3.3V) to the ADC values (0 to 1023).

The following lines capture the Analog input (0 to 3.3V) and convert it into digital value (0 to 1023). And then this digital values are divided by 4 to convert them into (0 to 255) and finally fed as PWM output in P0.1 pin of LPC2148. Here we are converting the values from 0-1023 to 0-255 by dividing it with 4 as PWM of LPC2148 has 8-Bit resolution (28).