This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R: Pulse counter Interrupt difficulty

Part Number: MSP432P401R


Okay, I'm a newbie and I'm trying to implement a pulse counter using the TACLK input pin on the launchpad. All I want is an interrupt to be triggered when i press a push button which will then increment a counter which is a global variable. I may be doing something stupid here but any help is appreciated

//*****************************************************************************
//
// MSP432 main.c template - Empty main
//
//****************************************************************************

#include "msp.h"

float g_fCount;

void main(void)
{
	
    WDTCTL = WDTPW | WDTHOLD;           // Stop watchdog timer

    TA1CTL = TASSEL_0 + MC_2 + TAIE; //TACLK source, Cont mode, enable TA1 Interrupt

    __enable_interrupt();
	
    while(1){

    }
}

void TA1_N_IRQHandler (void){
    g_fCount++; //Increment Counter
    TA1CTL = !TAIFG; //Set interrupt flag to 0
}

  • Well, timer is wrong peripheral in your case. You shall be using I/O port interrupt instead. Check source code examples, msp432p401_p1_03.c

  • But A timer can be configured as an event counter when using the TACLK as an external clock input no?

    My Code is now as follows but my TAR register does not increment when I apply a pulse for some reason:

    //*****************************************************************************
    //
    // MSP432 main.c template - Empty main
    //
    //****************************************************************************
    
    #include "msp.h"
    
    int16_t gCount;
    
    void main(void)
    {
        P7DIR |= !BIT2; //P7.2 INPUT
        P7SEL1 |= !BIT2; //P7.2 control bit one = 0
        P7SEL0 |= BIT2; //P7.2 control bit two = 1
    
        WDTCTL = WDTPW | WDTHOLD;           // Stop watchdog timer
    
        TA1CTL = TASSEL_0 + MC_2 + TAIE;    //TACLK source, Cont mode, enable TA1 Interrupt
    
        gCount +=  TA1R;
    
        __enable_interrupt();
    
        while(1){
    
        }
    }
    
    void TA1_N_IRQHandler (void){
        printf("Please work..");
    }

  • Ross said:
    TA1CTL = !TAIFG;

    To clear a single bit write TA1CTL &= ~TAIFG;.

**Attention** This is a public forum