abhishek046
Newbie level 4
- Joined
- Jan 26, 2014
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 69
I'm trying to control a TowerPro SG90 servo from my ez430-rf2500 board. I'm able to configure the Timers for PWM operation but there's absolutely no response from the servo. Just a small jerk at start and nothing.
As far as the connections are concerned, I've connected the grounds of ez430, servo and separate USB power supply for the servo to a common point. The pin 2.2 of the MCU is connected to the signal wire of the servo. The servo is powered by a USB power supply as mentioned earlier. Here's my code:-
Could someone tell me what I'm missing here? The code compiles perfectly.
As far as the connections are concerned, I've connected the grounds of ez430, servo and separate USB power supply for the servo to a common point. The pin 2.2 of the MCU is connected to the signal wire of the servo. The servo is powered by a USB power supply as mentioned earlier. Here's my code:-
Code C - [expand] 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 #include "msp430f2274.h" #define MCU_CLOCK 1100000 #define PWM_FREQUENCY 46 // In Hertz, ideally 50Hz. #define SERVO_STEPS 180 // Maximum amount of steps in degrees (180 is common) #define SERVO_MIN 700 // The minimum duty cycle for this servo #define SERVO_MAX 3000 // The maximum duty cycle unsigned int PWM_Period = (MCU_CLOCK / PWM_FREQUENCY); // PWM Period unsigned int PWM_Duty = 0; // % void main (void){ unsigned int servo_stepval, servo_stepnow; unsigned int servo_lut[ SERVO_STEPS+1 ]; unsigned int i; // Calculate the step value and define the current step, defaults to minimum. servo_stepval = ( (SERVO_MAX - SERVO_MIN) / SERVO_STEPS ); servo_stepnow = SERVO_MIN; // Fill up the LUT for (i = 0; i < SERVO_STEPS; i++) { servo_stepnow += servo_stepval; servo_lut[i] = servo_stepnow; } // Setup the PWM, etc. WDTCTL = WDTPW + WDTHOLD; // Kill watchdog timer TACCTL1 = OUTMOD_7; // TACCR1 reset/set TACTL = TASSEL_2 + MC_1; // SMCLK, upmode TACCR0 = PWM_Period-1; // PWM Period TACCR1 = PWM_Duty; // TACCR1 PWM Duty Cycle P2DIR |= BIT2; // P2.2 = output P2SEL |= BIT2; // P2.2 = TA1 output // Main loop while (1){ // Go to 0° TACCR1 = servo_lut[0]; __delay_cycles(100000); // Go to 45° TACCR1 = servo_lut[45]; __delay_cycles(100000); // Go to 90° TACCR1 = servo_lut[90]; __delay_cycles(100000); // Go to 180° TACCR1 = servo_lut[179]; __delay_cycles(100000); // Move forward toward the maximum step value for (i = 0; i < SERVO_STEPS; i++) { TACCR1 = servo_lut[i]; __delay_cycles(20000); } // Move backward toward the minimum step value for (i = SERVO_STEPS; i > 0; i--) { TACCR1 = servo_lut[i]; __delay_cycles(20000); } } }
Last edited: