ARM LPC2129 Mini Development Board – Interfacing Servo motor
The “ARM LPC2129 Mini Development Board – Interfacing Servo motor” wiki discussed here is in reference to the rhydoLABZ make LPC2129 Development Board-Mini, however it makes no difference even if the board used is either LPC2138 Development Board-Mini or LPC2148 Development Board-Mini.i.e, this interfacing guide is common for LPC2129/LPC2138/LPC2148 Mini Development Boards from rhydoLABZ.
Servos have simple electrical interface – they have 3 wires, one for power, one for ground and the other for the pulse train. Once the servo is powered, the signal wire is ready to receive signal in the form of pulse width modulation (PWM) from an external source.
The signal expects to be updated every 20 ms with a pulse between 0.5ms and 2.5ms. With a 1.5 ms pulse, the servo motor will be at the natural 90° position. With a 0.5 ms pulse, the servo will be at the 0° position, and with a 2.5 ms pulse, the servo will be at 180°. You can obtain the full range of motion by updating the servo with a value in between.
LPC2129 Mini Development Board has a dedicated connector (K13) to interface Servo motor. On the K13 regulated 5V is available on power supply pin, port pin connection from P1.24 is available on the signal pin and there is also a third pin connected to GND. Sample code to check servo motor is given below, once the code is loaded and executed, the servo starts to wipe continuously. Always use external DC power (wall wart or DC power supply) for powering, since the USB doesn’t provide required current for servo.
Schematic:
Sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
/************************************************************************************ * HEADER FILES * ************************************************************************************* * Requied Time = Value IN MR Register(x) / 30Mhz * *************************************************************************************/ #include<lpc21xx.h> #define SERVO 24 /* Servo connected to P1.24 */ /************************************************************************************ VARIABLE DECLARATION *************************************************************************************/ unsigned char servo_value; volatile unsigned char Timer_count=0; unsigned char servo_angle=0; unsigned char k=0; volatile unsigned char recdata; /************************************************************************************ * Function : PORT_Initial * * * * Description : Function for PORT Initialization * * * * Parameters : None * *************************************************************************************/ void PORT_Initial(void) { IO1DIR = 0x01000000; /* Servo pins as o/p */ IO0DIR = 0x00000001; /* Set direction for UART0 */ PINSEL0 = 0x00000005; /* Set pinsel for UART0 */ } /************************************************************************************ * Function : Convert_Angle * * * * Description : Function to calculate timer count for angle * * * * Parameters : k1 - angle * *************************************************************************************/ int Convert_Angle(unsigned char k1) { char timer_value; int temp; /* Converting angle to time count */ temp = k1*5; /* count for 0Degree = 25 */ timer_value = temp/9; /* Count/Degree = 5/9 */ timer_value = timer_value+25; /* eqn, count = (angle * (5/9)) + 25 */ return timer_value; } /************************************************************************************ * Function : Timer0_Init * * * * Description : Function for timer initialization * * * * Parameters : None * *************************************************************************************/ void Timer0_Init(void) { T0TCR = 0X02; /* Timer counter reset */ T0MR0 = 600; /* Value for 20us */ T0MCR = 0X0003; /* Interrupt & counter reset on match */ T0TCR = 0X01; /* Counter enabled */ } /*********************************************************************************** * Function : Uart_Init * * Description : UART_0 initialization function * * Parameter : None *************************************************************************************/ void Uart_Init(void) { U0LCR = 0X83; /* line control registor */ U0DLL = 0XC3; /* baud rate registor */ U0DLM = 0X00; /* baud rate registor */ U0LCR = 0X03; /* line control registor */ } /************************************************************************************ MAIN FUNCTION *************************************************************************************/ int main() { PORT_Initial(); /* Initialize port */ Uart_Init(); Timer0_Init(); /* Initialize timer */ while(1) { if(T0IR==1) /* Checking Timer */ { T0IR=0X01; /* Clear MR0 interrupt */ Timer_count++; /* Increment count */ if(Timer_count==125) T0MR0=525000; /* Load value to T0MR0 */ if(Timer_count==126) { T0MR0 = 600; /* Load value for 20us to TM0R0 */ Timer_count = 0; IO1SET |= 0X01000000; /* Make servo pin high */ } if( Timer_count == servo_value ) IO1CLR |=(1<< SERVO); /* Clear pin on value */ } if((U0LSR&0X01)==0X01) /* Checking reception */ { recdata=U0RBR; /* Store received data to a variable */ if(recdata=='a') /* When Received data 'a' */ servo_value = 120; /* Servo rotate for 180Degree angle */ else if(recdata=='b') /* When Received data 'b' */ servo_value = 30; /* Servo rotate for 0Degree angle */ } } } /************************************************************************************ END OF CODE *************************************************************************************/ |
Topics related to ARM LPC2129 Mini Development Board:
- ARM LPC2129 Mini Development Board – Overview
- ARM LPC2129 Mini Development Board – LED Interfacing
- ARM LPC2129 Mini Development Board – LCD Interfacing
- ARM LPC2129 Mini Development Board – UART0 Interfacing
- ARM LPC2129 Mini Development Board – UART1 Interfacing
- ARM LPC2129 Mini Development Board – Switches Interfacing
- ARM LPC2129 Mini Development Board – BUZZER Interfacing
- ARM LPC2129 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2129 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2129 Mini Development Board – Interfacing Servo motor
- ARM LPC2129 Mini Development Board – CAN Interfacing
Resources:
- Softwares
- Datasheets
How to buy:
- Click here to buy rhydoLABZ ARM LPC2138 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2148 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2129 Mini Development Board
- Click here to buy rhydoLABZ Servo motor
Support:
Please share your ideas with us, visit our forum for discussion