#include #include volatile unsigned long timerA_tick_count = 0; volatile unsigned int pwm0, pwm1; interrupt(TIMERA0_VECTOR) wewtimer_isr0() { TA0CCR0 = 0xFFFF; /* set at overflow */ TA0CCTL0 = OUTMOD_SET; /* note: don't interrupt */ } interrupt(TIMERA1_VECTOR) wewtimer_isr() { timerA_tick_count++; switch (TA0IV) { /* reset intrerupt */ case TAIV_OVERFLOW: TA0R += 65535-8000; /* count another ms */ /* * Note that at this point, both CC units should have SET * their respective output bits when TAR hit 0xFFFF */ TA0CCTL0 = OUTMOD_RESET + CCIE; /* reset and int at count */ TA0CCR0 = pwm0; /* set new count */ TA0CCTL1 = OUTMOD_RESET + CCIE; TA0CCR1 = pwm1; break; case TAIV_CCR1: TA0CCR1 = 0xFFFF; /* set at overflow */ TA0CCTL1 = OUTMOD_SET; /* note: don't interrupt */ break; } } void delay(unsigned long ms) { unsigned long start = timerA_tick_count; while (timerA_tick_count - start <= ms) ; // spin. } void main() { int i; /* * Change clock to approx 8MHz (prescaled from internal 1.1MHz */ BCSCTL1 = CALBC1_8MHZ; // Set range DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */ /* * set up pin 6 as timer PWM output */ P2SEL = 0; /* use port2 pins as outputs */ P1SEL |= 1<<6; // TA0CCR1 output on pin 6 P1DIR |= 1<<6; /* * Set up timer A */ TA0CTL = TASSEL_SMCLK + MC_CONT + TAIE; /* SMCLK, continuous mode */ TA0R = 65536-8000; /* initial value */ TA0CCTL1 = OUTMOD_RESET+CCIE; // timer outputing PWM TA0CCTL0 = OUTMOD_RESET+CCIE; // timer outputing PWM eint(); /* global interrupts on */ /********************************************* * the big question. Does changing TA0CCR0 change the behavior of TA0CCTL1 ? *********************************************/ TA0CCR0 = pwm0 = 65536-4000; /* 50% while we test pwm1 */ while (1) { for (i=100; i < 8000; i += 50) { TA0CCR1 = pwm1 = (65535-8000)+i; delay(100); } } }