#include "input_capture.h" #include "inc/msp432p401r.h" void (*capture_task)(uint16_t time); // Initialize Timer A0 in edge time mode to request interrupts on // the rising edge of P7.3 (TA0CCP0). The interrupt service routine // acknowledges the interrupt and calls a user function. void TimerA0CaptureInit(void (*task)(uint16_t time)) { capture_task = task; P7->SEL0 |= 0x08; P7->SEL1 &= ~0x08; // configure P7.3 as TA0CCP0 P7->DIR &= ~0x08; TIMER_A0->CTL &= ~0x30; // halt Timer A0 TIMER_A0->CTL = 0x200; // SMCLK TIMER_A0->CCTL[0] = 0x4910; // capture on rising edge, synchronous capture, capture mode, interrupt enabled TIMER_A0->EX0 &= ~0x7; // input clock divider /1 NVIC->IP[2] = (NVIC->IP[2] & 0xFFFFFF00) | 0x00000002; // priority 2 // interrupts enabled in the main program after all devices initialized NVIC->ISER[0] = 0x100; // enable interrupt 8 in NVIC TIMER_A0->CTL |= 0x24; // reset and start Timer A0 in continuous up mode } void TA0_0_IRQHandler(void) { TIMER_A0->CCTL[0] &= ~0x1; // acknowledge capture/compare interrupt capture_task(TIMER_A0->CCR[0]); // execute user task } // Left Encoder A connected to P10.5 (J5) // Right Encoder A connected to P10.4 (J5) // user function, time is up-counting timer value when edge occurred in units of 0.083 usec // called when P10.4/.5 (TA3CCP0/1) edge occurs void (*capture_task0)(uint16_t time); void (*capture_task1)(uint16_t time); // Initialize Timer A3 in edge time mode to request interrupts on // the rising edges of P10.4 (TA3CCP0) and P10.5 (TA3CCP1). // Interrupt service routines acknowledge the interrupt and call a user function. // Assumes: low-speed subsystem master clock is 12 MHz void TimerA3CaptureInit(void (*task0)(uint16_t time), void (*task1)(uint16_t time)) { // write this code } // The rising edge of P10.4 will cause an interrupt void TA3_0_IRQHandler(void) { // write this code } // The rising edge of P10.5 will cause an interrupt void TA3_N_IRQHandler(void) { // write this code }