[SOLVED] MSP430 EZ430-RF2500 Servo interface problem

Status
Not open for further replies.

abhishek046

Newbie level 4
Joined
Jan 26, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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:-


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);
 
     }
   }
}

Could someone tell me what I'm missing here? The code compiles perfectly.
 
Last edited:

I think your pin configuration is wrong msp430 EZ430 comes with msp430f2274 controller and form its pin diagram your PWM pin must be P2.3 for TA1 P2.2 is TA0 any nice copy from here https://mitchtech.net/msp430-launchpad-pwm/



strongly recommended to check the PWM before giving to servo.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Thanks! I was fiddling with TA1 while checking the TA0 pin. Just one last question.
Do the +V & the Signal pin of the servo need to work at the same voltage levels for proper operation or can the signal be 3.3V while the +V be 5V?
 

I think both works good at 3.3v level you can see the link in my previous post.
 

Hello!

Ok, apparently you solved the problem.
However, here are a few remarks about your program:
1. The watchdog timer should be the absolute first action in your program. In your case, you have a loop
filling the LUT first. Well, it might be short enough to work, but in some other cases, your program will keep
rebooting, you will not understand why and your hair will turn gray.

2. You use a lot of __delay_cycles, and that's not the proper way to work because you will just consume
processor cycles for nothing. Imagine that you want to do other actions, you couldn't by using this technique.
Apparently you know how to use timers, so why not using a second one to do the whole thing?

3. In this case, you wouldn't need a while(1) loop.

Dora
 
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…