Jump to content
Sign in to follow this  
Jak

Servos and analogWrite problem [FIXED]

Recommended Posts

When programming recently, I found that I had some trouble controlling a motor at the same time as several servo. The servos would go all crazy, and the motor wouldn't work. I guessed that this was because the timers were interfering, or not enough timers, or similar. Digging into the servo library, and the analogWrite function, I found that they're both trying to use Timer A. Thus, I modified the analogWrite function.

 

In file energia/hardware/msp430/cores/msp430/wiring_analog.c , I commented out lines 110 to 123 (inclusive). Below is the code commented out.

			case T0A1:                              // TimerA0 / CCR1
                                TA0CCR0 = PWM_PERIOD;           // PWM Period
                                TA0CCTL1 = OUTMOD_7;            // reset/set
                                TA0CCR1 = PWM_DUTY(val);       // PWM duty cycle
                                TA0CTL = TASSEL_2 + MC_1 + analog_div;       // SMCLK, up mode
                                break;
#if defined(__MSP430_HAS_TA3__) || defined(__MSP430_HAS_T0A3__) 
 			case T0A2:                              // TimerA0 / CCR2
                                TA0CCR0 = PWM_PERIOD;           // PWM Period
                                TA0CCTL2 = OUTMOD_7;            // reset/set
                                TA0CCR2 = PWM_DUTY(val);       // PWM duty cycle
                                TA0CTL = TASSEL_2 + MC_1+ analog_div;       // SMCLK, up mode
                                break;
#endif

This may only work using the G2553, but if you're stuck with a G2231 from a rev 1.4 board, just sample a new chip :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×