EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Re: Launchpad Help: Six Potentiometers + Six Servos + MSP430G2553

Started by Matthias Weingart April 12, 2012
"tech_juggernaut" :

>
> http://www.43oh.com/forum/viewtopic.php?f=9&t(4&sidB1919d1925c1b25e4\
> 4442df3ea18367&start

> // Timer A0 interrupt service routine
> #pragma vector = TIMER0_A0_VECTOR
> __interrupt void Timer_A0(void) {
> counter++; // Increase counter
> if(counter == 0x07)
> counter = 0; // Counter range is 0-6, the last
> count is used to add 5ms delay
>
> P2OUT &= ~(SERVO_OUTPUTS); // Clear ports
> if(counter == 0x06) {
> CCR0 = 2500 - (servoPosition[0] + servoPosition[1] +
> servoPosition[2] + servoPosition[3] + servoPosition[4] +
> servoPosition[5]);
> ADC10CTL0 &= ~ENC;
> while (ADC10CTL1 & BUSY);
> ADC10SA = (unsigned int)&adcValues[0];
> ADC10CTL0 |= ENC + ADC10SC;
> } else {
> P2OUT |= servoOn[counter]; // Set port of the
> current servo
> CCR0 = servoPosition[counter]; // Set time for the
> current servo
> }
> }

In this case you do the PWM in software. As far as I have seen you can have
some jitter (in the microseconds range, it is due to the interrupt response
time that can vary) and with sensitive servos you see this jitter as a small
mechanical vibration on the servo. A full hardware PWM would have ja much
lower jitter (using the compare registers).

Another point: waiting in a interrupt routine is not a good solution:
"while (ADC10CTL1 & BUSY);"

M.

Beginning Microcontrollers with the MSP430


Memfault Beyond the Launch