Servo Motors aren’t used for continuous rotation like normal DC Motors. They are often used in closed loop position control applications. One of the best application of the servo motor is the robotic hand movement or tilt or pan movement of a CCTV camera. Even though stepper motors are also used for accurate position control, the main advantage of servo motors over stepper motors is the power consumption. After achieving a desired position, the servo motor stops consuming power. But in case of a stepper motor, after moving to a desired position, the stepper motor draws power to lock itself to that position. Hence, servo motors have the advantage in low power devices. In this project, a simple DC Servo Motor is controlled using an ARM7 based MCU LPC2148. Different positions of the servo motor are achieved to demonstrate its functioning.

Circuit Diagram

Components Required

If we are using a development board or a stand – alone ARM7 board, we need some additional components in order to interface the Servo Motor with the LPC2148 MCU. So, you might need the following components.

LPC2148 MCU based ARM7 development board or stand – alone board Tower Pro SG90 Servo Motor (or any other servo motor) Power Supply (Separate for MCU and Servo Motor) BSS138 N – Channel MOSFET (or any equivalent transistor) 4 X Push Buttons 4 X 4.7 KΩ Resistors 2 X 10 KΩ Resistors Connecting wires USB – to – Mini USB Cable

Circuit Design

Since we need to control a Servo Motor (this applies for any motor control), we shouldn’t connect the motor directly to the MCU. We need a driver circuit like a simple transistor to interface a Servo Motor with LPC2148. So, first step is to construct the driver circuit consisting of the MOSFET, some resistors and the servo motor itself. Note: The driver circuit for the servo motor is to drive the control signal. Although the 3.3V signal from the LPC2148 might be sufficient, it is better to use a separate driver circuit. After connecting the driver circuit, the next step is to connect 4 push buttons to the LPC2148 in order to change the duty cycle of the PWM Signal. Note: A Potentiometer can also be used to linearly vary the duty cycle of the output PWM. This requires the implementation of the internal ADC Module. The other necessary components like crystal oscillator, USB – to – UART converter, voltage regulators, etc. are already on the development board or stand – alone board. Note: Since we are using an LPC2148 development board, the push buttons are already embedded on – board. So, only the connections regarding the servo motor are made in the project.

Working of the Project

The objective of the project is to interface a servo motor with ARM7 LPC2148. The working of the project lies in the functioning of the servo motor. We know that a PWM signal is used to control the position of the servo motor’s shaft. So, PWM plays an important role in the functioning of the servo motor. More information about PWM in LPC2148 can be found here. Coming back to our project, we need to generate PWM signal in the LPC2148 and control the duty cycle of the PWM signal using the push buttons. Four push buttons are used for 4 different duty cycles i.e. 25%, 50%, 75% and 100%. When a corresponding button is pressed, the internal PWM generator adjusts the PWM signal as per the program and generates a proportionate PWM signal. This PWM signal, which is given as the control signal to the servo motor, determines the position of the shaft. The working of the project can be understood better by analyzing the program / code written.

Code

Understanding the Program

There are two main aspects of the program for Servo Motor interfacing with LPC2148: Generation of Clock signal using PLL Module and Generation of PWM signal using PWM generator. First, we see the generation of clock using PLL. The system clock CCLK and peripheral clock PCLK are set to user preferred values using the on – chip PLL of the LPC2148. The limit of the clock signal frequency for LPC2148 MCU is 60 MHz. So, using the following lines of code in the program, we can generate a 60 MHz CCLK and a 60 MHz PCLK. A detailed information and tutorial about PLL in LPC2148 can be found here. First, we need to enable the PLL0 module and set the multiplier and divider values. For that, the following commands can be used. PLL0CON = 0x01; PLL0CFG = 0x24; Next step is to lock these multiplier and divider values using a feed sequence. PLL0FEED = 0xAA; PLL0FEED = 0x55; Now wait for the PLL to lock to the values and connect the PLL module. while (! (PLL0STAT & 0x00000400)); PLL0CON = 0x03; Once again, lock the values with feed sequence and also enable the PCLK to same frequency as CCLK. PLL0FEED = 0xAA; PLL0FEED = 0x55; VPBDIV = 0x01; With these instructions, the CCLK and PCLK are set at 60 MHz using the PLL0 module. Next step is to initialize the PWM Module and generate PWM signal. A detailed information about PWM in LPC2148 is explained here. PWMPCR = 0x0; //Selecting Single Edge PWM (it is selected by default) PWMPR = PWMPRESCALE-1; // PWMPRESCALE=60 for 1 micro-second resolution PWMMR0 = 10000; // Duration of the period is set to 10 ms PWMMR5 = 2500; // Pulse duration is set to 2.5 ms PWMMCR = (1«1); // PWMTC is reset on PWMMR0 match PWMLER = (1«5) | (1«0); // update MR0 and MR5 PWMPCR |= (1«13); // PWM output is enabled PWMTCR = (1«1) ; //Reset PWM TC & PR PWMTCR = (1«0) | (1«3); // Finally, enable counters and PWM Mode With the above mentioned commands, the PWM5 is set and generates PWM signal. Final step is to control the Pulse duration with the help of buttons. If button connected to P0.15 is pushed, the duty cycle should be 50%. So, the following code will do that. if( !((IO0PIN) & (1«15)) ) // Check P0.15 { PWMMR5 = 5000; //T-ON=50% PWMLER = (1«5); //Update Latch Enable bit for PWMMR5

Comment * Name * Email * Website

Δ

Interfacing a Servo Motor with ARM7 LPC2148 - 53Interfacing a Servo Motor with ARM7 LPC2148 - 76Interfacing a Servo Motor with ARM7 LPC2148 - 68Interfacing a Servo Motor with ARM7 LPC2148 - 66Interfacing a Servo Motor with ARM7 LPC2148 - 32Interfacing a Servo Motor with ARM7 LPC2148 - 38Interfacing a Servo Motor with ARM7 LPC2148 - 83Interfacing a Servo Motor with ARM7 LPC2148 - 80Interfacing a Servo Motor with ARM7 LPC2148 - 20Interfacing a Servo Motor with ARM7 LPC2148 - 10Interfacing a Servo Motor with ARM7 LPC2148 - 74Interfacing a Servo Motor with ARM7 LPC2148 - 34Interfacing a Servo Motor with ARM7 LPC2148 - 85Interfacing a Servo Motor with ARM7 LPC2148 - 87