Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 63818

Forum Post: PWM msp430F5529 question about timing

$
0
0
I have looked at the tutorials for PWM and I understand how the math to get the PWM period is generated. The servos I am using say they expect a pwm pulse every 20ms and the pwm pulse is from 1 2ms to 2ms So i have set the period to be 1045000/ 2 * 10450, which gives me the 20ms period, then I move the duty cycle from 5% to 10% which is to give the required pulse to the servo It only seems to work occasionally and doesn't seem to be very accurate. I am wondering where I am going wrong. I won't have access to an oscilloscope till monday. Any help or where to look in the data sheet for PWM generation with TImerA, I only see info for timer D here is the code just to cycle it from 0-180 degrees, it works ocassionally then gets stuck also if I use the ACLK at 32768 and I use a pwm period of 128 * 2 The max resolution I can get out of that is 128 unique locations for the servo? #include void PWM_INIT_TIMERA(); int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT PWM_INIT_TIMERA(); int i = 0; while(1) { _delay_cycles(8000); for(i = 545 ; i 545 ;i--) { _delay_cycles(8000); TA1CCR1 = i; // TA1CCR2 = 1000-i; } } } void PWM_INIT_TIMERA() { P2DIR |= BIT0 + BIT5; // P2.0 P2SEL |= BIT0 + BIT5; // P2.0 TA1CCR0 = 10450; // PWM Period/2 TA1CCTL1 = OUTMOD_6; //CCR1 toggle/set TA1CCR1 = 523; // CCR1 PWM duty cycle TA1CTL = TASSEL_2 + MC_1 + TACLR; // ACLK, continuos mode /* TA2CCR0 = 128; // PWM Period/2 TA2CCTL1 = OUTMOD_6; //CCR1 toggle/set TA2CCR1 = 0; // CCR1 PWM duty cycle TA2CTL = TASSEL_1 + MC_2 + TACLR; // ACLK, continuos mode */ }

Viewing all articles
Browse latest Browse all 63818

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>