This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Servo Control With Msp430 g2553

Other Parts Discussed in Thread: MSP430G2553

Hi all,

I am trying to control a common rc servo with launchpad. I am using timer for pwm signals. But my code doesn't work. I am stuck. Basic codes from ti tutorials don't work either.

My servo is : SM-s3317s

I power it with arduino uno (5V and GND) also connect the control wire to launchpad (p1.2) . I checked the servo with arduino, it doesnt have any problem. 

I tried to adjust pwm period to 20 ms and also tried to  have high pulses between duration of 1ms-2ms as it is seen in the code.

my mcu is : g2553

Here is my code :

#include <msp430g2553.h>

#define SERVO_BIT BIT2
#define SM_clk 1100000
#define servo_freq 50

int i;

void init()
{
int PWM_period = SM_clk /servo_freq;

P1DIR |= SERVO_BIT; //direction is set
P1SEL |= SERVO_BIT;// port 1 function is set. 
TA0CCR0 = PWM_period-1; // pwm period
TA0CCR1 = 0; //duty cycle = TA0CCR0/ TA0CCR1
TA0CCTL1 = OUTMOD_7;
}
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
init();
TA0CTL=TASSEL_2+MC_1; // starting timer by setting clock source SMCLK of timer and UP mode

while(1){
TA0CCR1 = 1100;
__delay_cycles(1000000);
TA0CCR1 = 1300;
__delay_cycles(1000000);
TA0CCR1 = 1500;
__delay_cycles(1000000);
TA0CCR1 = 1800;
__delay_cycles(1000000);
TA0CCR1 = 2200;
__delay_cycles(1000000);

}

return 0;
}

Does anyone have any suggestions??Is there something i did wrong??

Thanks for your time and answers!!

Erdem

  • Erdern,

    if you debug the code, especially in init() function, with what value will the TA0CCR0 be initialized?

    I am guessing this is due the problem of SM_clk definition. I think you should do the following:

    #define SM_clk 1100000UL

    Please notice the UL suffix which will make the compiler assign a 32 bit value for it. If not using it, i think the compiler will assign it as a normal integer 16 bit value.

**Attention** This is a public forum