/* www.MicroDigitalEd.com * p6_7.c Waveform generation using Timer_A0.4 compare * * This program uses TA0.4 in compare mode to generate * periodic signal on pin P2.7. * System clock is running at 3 MHz. Clock input dividers are * set to divide by 8 and 8. TA0 is set to continuous mode. * TA0.4 is configured for compare mode. When the * TA0R counter value matches TIMER_A0->CCR[4], the output is set to toggle. * It also triggers an interrupt. In the interrupt handler, * 11719 is added to TIMER_A0->CCR[4] so that the next toggle occurs * 11719 cycles (250 ms) later. Both P2.7 and P2.1 toggle at 250 ms period. * * Since none of the LEDs is connected to a Timer_A output, * Port Map is used to connect the TA0.4 output to P2.1, which * is connected to the green LED. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" int main(void) { void redirect(void); __disable_irq(); /* set up TA0.4 to do compare */ TIMER_A0->CTL = 0x02E4; /* SMCLK, ID = /8, continuous mode, TA clear */ TIMER_A0->EX0 = 7; /* IDEX = /8 */ TIMER_A0->CCTL[4] = 0x80; /* OUTMOD = toggle */ TIMER_A0->CCR[4] = 11719; /* toggle point */ TIMER_A0->CCTL[4] |= 0x10; /* enable CC interrupt */ /* Configure P2.7 as Timer A0.4 compare output */ P2->SEL0 |= 0x80; P2->SEL1 &= ~0x80; P2->DIR |= 0x80; redirect(); /* connect TA0.4 output to pin P2.1 */ NVIC_SetPriority(TA0_N_IRQn, 3); /* set priority to 3 in NVIC */ NVIC_EnableIRQ(TA0_N_IRQn); /* enable interrupt in NVIC */ __enable_irq(); /* global enable IRQs */ while (1) { } } void TA0_N_IRQHandler(void) { TIMER_A0->CCTL[4] &= ~1; /* clear interrupt flag */ TIMER_A0->CCR[4] += 11719; /* schedule next toggle */ } /* This function connects the output of TA0.4 to pin P2.1 */ void redirect(void) { PMAP->KEYID = 0x2D52; /* unlock PMAP */ P2MAP->PMAP_REGISTER1 = PMAP_TA0CCR4A; /* 23, map P2.1 to TA0.4 */ P2->DIR |= 2; /* set up P2.1 to take TA0.4 output */ P2->SEL0 |= 2; P2->SEL1 &= ~2; PMAP->CTL = 1; /* lock PMAP */ PMAP->KEYID = 0; }