bluehash 1,581 Posted August 27, 2010 Share Posted August 27, 2010 Just found this while browsing the web. Submitter's name is Vihapuu. So credit goes to him. Youtube: His code is posted on pastebin. So I'm archiving it here just in case. #include #include #include "msp430G2231.h" #define TEST2 1 #define SERVO_0 650 #define SERVO_180 2350 #define SERVO_COUNT 4 #define SETSERVO(servo, pos) periods[servo].cycle = servopos(pos); typedef struct period_t_ { uint16_t cycle; uint8_t pins; } period_t; period_t periods[1 + SERVO_COUNT]; uint8_t period = 0; void mysleep(uint16_t i); uint16_t servopos(uint8_t pos); void initperiod(uint8_t period, uint16_t cycle, uint8_t pins); int main(void) { WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */ initperiod(0, 20000, 0x00); initperiod(1, servopos(90), BIT5); initperiod(2, servopos(90), BIT4); initperiod(3, servopos(90), BIT3); initperiod(4, servopos(90), BIT2); P1OUT = 0x00; P1DIR |= BIT5; P1DIR |= BIT4; P1DIR |= BIT3; P1DIR |= BIT2; CCTL0 = CCIE; CCR0 = 65535; TACTL = MC_1 + TASSEL_2 + TACLR; //_BIS_SR(LPM0_bits + GIE); _BIS_SR(GIE); while (1) { uint16_t i; SETSERVO(1, 90); SETSERVO(2, 90); SETSERVO(3, 0); mysleep(100); for (i = 90; i != 25; i -= 5) { SETSERVO(2, i); mysleep(3); } SETSERVO(2, 25); mysleep(100); SETSERVO(3, 130); for (i = 0; i SETSERVO(2, 15); SETSERVO(3, 120); mysleep(5); SETSERVO(2, 25); SETSERVO(3, 130); mysleep(5); } mysleep(100); SETSERVO(2, 10); for (i = 0; i SETSERVO(1, (90 - 30) + i); mysleep(5); } for (i = 0; i SETSERVO(1, (90 + 30) - i); mysleep(5); } } } #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A_0(void) { P1OUT = periods[period].pins; CCR0 = periods[period].cycle; if (period ++ >= SERVO_COUNT) period = 0; } void mysleep(uint16_t i) { uint16_t y, x; y = i; while (--y != 0) { for (x = 0; x } } uint16_t servopos(uint8_t pos) { return (uint16_t) ((SERVO_180 - SERVO_0) * (float) pos / 180) + SERVO_0; } void initperiod(uint8_t period, uint16_t cycle, uint8_t pins) { periods[period].cycle = cycle; periods[period].pins = pins; } /* vim: set sw=8 noet: */ Quote Link to post Share on other sites
GeekDoc 226 Posted August 27, 2010 Share Posted August 27, 2010 Can't tell from the video; are the servos hooked directly to the 430 pins, or through an interface? Quote Link to post Share on other sites
gatesphere 45 Posted August 27, 2010 Share Posted August 27, 2010 One looks to be attached directly to the pins (looks like this user chose the male pin headers) and the other one I couldn't see the connection point, or even jumper wires... it might have been attached to the breadboard under the LP though. Quote Link to post Share on other sites
bluehash 1,581 Posted August 27, 2010 Author Share Posted August 27, 2010 Can't tell from the video; are the servos hooked directly to the 430 pins, or through an interface? The signal wire comes in from the Launchpad. Looks like he is powering the servos externally through a voltage regulator(~5V). You can see the breadboard around 0.04 minutes. [EDIT] gatesphere raced me to it. Quote Link to post Share on other sites
GeekDoc 226 Posted August 27, 2010 Share Posted August 27, 2010 Thanks gatesphere & bluehash. My pause reaction wasn't fast enough. HobbyKing.com has some pretty cheap servos. This might be fun! -Doc Quote Link to post Share on other sites
jsolarski 94 Posted August 30, 2010 Share Posted August 30, 2010 this is pretty much what i was looking for, hopefully i can translate the code to a more readable form....... as for servos, I personally use the HS-311 from Hitec, this is a decent analog servo usually under $15 USD per servo. Quote Link to post Share on other sites
bluehash 1,581 Posted August 30, 2010 Author Share Posted August 30, 2010 I have a Futaba s3003 servo lying around, which I can donate, if anyone wants to give it a try. You may pass it on once your done or keep it. Quote Link to post Share on other sites
saigai 0 Posted September 8, 2010 Share Posted September 8, 2010 Hi all! I'm the author of the video in question. I was pleasantly surprised to find that my little learning experiment was being linked to by msp430 related sites In the video I used the TP1 and TP3 connections (if I remember the names correctly, near the USB anyway) on the launchpad to draw 5V directly from USB. It gives enough juice to do some basic servo testing. For more servos however I had to switch to an external power supply. In the future I hope to build a little robot arm/leg. I'm just not sure about what material to use yet. Quote Link to post Share on other sites
jsolarski 94 Posted September 8, 2010 Share Posted September 8, 2010 you could use something like shapelock for your prototyping its an easy plastic to work with and melts at 150degrees F http://shapelock.com/ there are other similar products out there but this is the one i found in the US But thanks for the Great code too!! Quote Link to post Share on other sites
bluehash 1,581 Posted September 8, 2010 Author Share Posted September 8, 2010 Hi saigia! First welcome to the forums! In addition to shapelock( never knew about this ) which jsolarski mentioned, there is lexan which Lynxmotion uses alot for their robots. You could also use acrylic sheets from Ponoko, which was featured on Sparkfun. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.