Jump to content
43oh

Servo Control With Msp430 g2553


Recommended Posts

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


Edited by bluehash
Please use CODE TAGS next time.
Link to post
Share on other sites
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...