/* www.MicroDigitalEd.com * p11_4.c Toggling P2.7 at 30 Hz using Timer_A0.4 PWM * * This program uses Timer_A0.4 to generate PWM output at 30 Hz * and 33.3% duty cycle. * Subsystem Master Clock (SMCLK) running at 3 MHz is used. * Timer_A0 is configured to up/down mode from 0 to 50,000-1, which * is loaded in TIMER_A0->CCR[0]. * The timer counter roll over interval is: * 3,000,000 / 50,000 / 2 = 30 Hz. * TIMER_A0->CCR[4] is loaded with 50000/3 and CCR4 is configured * as toggle/reset mode. The output is clear to 0 when the TAxR * counter reaches TAxCCR4 on the up count and toggled to 1 when * the TAxR counter reaches TAxCCR4 on the down count. So the output * is 1 when TAxR is below the value of TAxCCR4. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" void delayMs(int n); int main(void) { /* Configure P2.7 as Timer A0.4 output */ P2->SEL0 |= 0x80; P2->SEL1 &= ~0x80; P2->DIR |= 0x80; /* configure TimerA0.4 as PWM */ TIMER_A0->CCR[0] = 50000-1; /* PWM Period */ TIMER_A0->CCR[4] = 50000/3; /* CCR4 PWM duty cycle */ TIMER_A0->CCTL[4] = 0x40; /* CCR4 toggle/reset mode */ TIMER_A0->CTL = 0x0234; /* use SMCLK, up/down mode, clear TA0R register */ while (1) { } }