EmbeddedRelated.com
Forums

Launchpad Help: Six Potentiometers + Six Servos + MSP430G2553

Started by tech_juggernaut April 10, 2012
Is this possible? I'd like to control six servos, individually, with six potentiometers by using all six capture/compare registers of Timer_A0 and Timer_A1 in the 20-Pin G2553 on my Launchpad.

I've built a robotic arm and I want my code to be able to constantly send a PWM to each servo so that they can maintain their positions, as well as change and update each of their positions using the pots. I've written code to try to control only two. My code so far is:

------------------------


----------------------

I'm not sure what to do at this point, it only controls one servo and the other doesn't move when I turn the pot.

Thanks for your help!

Beginning Microcontrollers with the MSP430

The in built PWM on the MSP430 works by using channel 0 in each timer to
set the period of the PWM and then CH1 and CH 2 to set the duty cycle.
If you want 6 channels you will need to manually handle the timing and
control of each pin.

Here you are using the count up mode, which means that CCR0 is already
committed to one task. This is conventionally how you would handle PWM,
so 4 channels would be the limit. You can get around this in several
ways. The two simplest would be to keep your current timer set up using
CCR0 then to use a single timer to try and track the 3 duty cycle times.
The obvious down side to this is that you will have an issue when the
times are very close together and your ISR's would be more com plex than
is desirable, so you would probably need to run the micro at a higher
clock rate.

The second method would be to set the timers to free run mode and use a
single timer for each channel. Fix the period, and calculate the duty
cycle, then on alternate interrupt events set the timer control to
autoset/reset the associated pin. calculations could be done in the
foreground, which is simply DutyISR = X, PeriodISR = Period - X. Set
pulse to SET on PeriodISR, to reset on DutyISR. Obviously use the timer
Compare mode. This is the better method since, by using the outmatic pin
set modes you minimise the jitter you'd get with method 1, since the ISR
doesn't need to occur on the exact time to control the pin, it can occur
during 'dead time', as it just needs to flip a couple of control bits
and adjust the compare value. Since the clock rolls over you don't need
to bother adjusting for that. this method also allows you to use the
Timer overflow to maintain a real time clock if that's needed.

Cheers

Al
Thanks Onestone, when you say free run mode are you talking about continuous? That makes sense and definitely sounds like the way to go, instead of counting up to CCR0 it would just count up to FFFF, leaving the CCR0s free.

Would you mind giving me an example of how the code should be rewritten regarding the second suggestion?

I really appreciate your time, thanks again.
Hi, you're welcome, on the code side, firstly I do assembler only on the
MSP, never had cause to use C, secondly in a few minutes I'm off to
hospital for some pretty major spinal surgery, so no time. yes I do mean
continuous mode best of luck

Cheers

Al
Al,

May your surgery and recovery go well.

Emmett Redd Ph.D. mailto:E...@missouristate.edu
On Tue, Apr 10, 2012 at 1:51 PM, Redd, Emmett R
wrote:

> May your surgery and recovery go well.

Seconded. Your participation in this group is very appreciated. I have
learned much from reading your posts.

- Bart
On Tue, Apr 10, 2012 at 3:11 AM, tech_juggernaut wrote:

> Is this possible? I'd like to control six servos, individually

IIRC there was some multi-channel servo-control code posted to the
43oh forums at some point.

http://www.43oh.com/forum

-p.
Al,

I'm hoping for a pain-free and very speedy recovery.

Bob

Al,

No worries, just get well soon!! I can't thank you enough, anyone that has time to help a complete stranger with a project the day before surgery is a friend of mine. Hope all is well, speedy recovery...

-Jake
Good luck Al.