I am trying to use the timers on the microcontroller in order to count up to 10us then add 1 to the int timer. I intend to use this in a project I am doing where I count the time between pulses from a circuit I have built. The code is as flows:

#include <msp430fr4133.h>
#include <driverlib.h>

unsigned int count = 0;
unsigned int button1 = 0;
unsigned int button2 = 0;

#pragma vector=TIMER0_A0_VECTOR
__interrupt void TimerA0_ISR0(void)

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

    // Disable the GPIO power-on default high-impedance mode
    // to activate previously configured port settings
    //Setting up buttons
    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3); 
    GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3);
    GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3);

    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4);
    GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4);
    GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4);

    //Setting up timer to count to 10us 
    TA0CTL = TASSEL_2|ID_0|MC_1|TACLR;   //SMCLK, divider 1, up mode, clear timer, interrupt enable, interrupt pending
    TA0CCR0 = 10000;      //count to 10us = 10/1MHz/1

      button1 = GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3);
        TA0CCTL0 &= ~ CCIE;              //disable interrupt if button 1 pressed
        timer = 0;    
      button2 = GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN4);
        TA0CCTL0 |= CCIE;                //enable interrupt if button 2 pressed

The way the code should work is when the second button is pressed the interrupt will enable and the counting will begin. Then when the first button is pressed the interrupt will disable and reset the timer.

The problem I am having is that when the interrupt is enabled, it will never enter the interrupt and increase int timer. I have set up the timer using the user guide and datasheet but I am unsure if I have set it up correctly. If anyone could shed some light on this problem it would be much appreciated!


The code has been changed slightly to fix suggested problems but still does not work.

  • \$\begingroup\$ ~COV does not do what you think it does. \$\endgroup\$
    – CL.
    Commented Apr 8, 2016 at 18:40

2 Answers 2


CL is right, your use of ~COV is wrong and is ruining your other settings. Here is what happens:

COV is defined in memory as:

 #define COV (1 << 1)

Inverting COV (with ~COV) does not just invert that bit, it actually inverts the entire COV field. So if you know that COV is (in binary) 0000 0000 0000 0010, then ~COV becomes 1111 1111 1111 1101. You then take this value and OR it with everything else you just carefully set up, effectively wiping out those settings.

Your TA1CCTL1 register is thus ALWAYS set to 1111 1111 1111 1101, or just ~COV.

If you want to clear COV bit, you need to do it properly:

TA1CCTL1 &= ~COV; 

If you also want to clear bits A and B (for example), you could do:

TA1CCTL &= ~(COV | A | B);
  • \$\begingroup\$ Thank you, I understood this to mean that it would set COV to bit 0. I have made changes to this and went back through the datasheet are reconfigured my timer, however my code still isn't working and I have no clue as to why. I have updated the code above with the changes I've made. If you could help with why this is it would be much appreciated. \$\endgroup\$ Commented Apr 11, 2016 at 11:18

The interrupts were not correctly enabled!

The way this was fixed is by using __enable_interrupt();. This function fixed the interrupts and allowed them to work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.