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.

# How to property disable a timer?

Hi,

I am trying to interface a buzzer to MSP430F67xx. A transistor is installed between Pin4.7 and the buzzer. The buzzer will ring continuously when turned on. So I feel I can use one of the timers to generate a non-continuous ringing to save some power. I am having some trouble to turn off the buzzer. The following is my code:

#include "io430.h"
void buzzer(char tag, int duration);
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P4SEL &= ~BIT7;
P4DIR |= BIT7;
P4OUT &= ~BIT7;

buzzer(1, 10000);

//setup interupt port turn off buzzer
P1IES |= BIT7;
P1IFG &= ~BIT7;
P1IE |= BIT7;
__enable_interrupt();

__bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 w/ interrupts

return 0;
}

void buzzer(char tag, int duration)
{
if(tag)
{
TA1CCTL0 |= CCIE;                        // CCR0 interrupt enabled
TA1CCR0 = duration;
TA1CTL = TASSEL_1 | MC_1 | TACLR;       // ACLK, up mode, clear TAR
}else
{
TA1CCTL0 &= ~ CCIE;
TA1CTL |= MC_0;
P4OUT &= ~BIT7;
}
}

#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
P4OUT ^= BIT7;                          // Toggle P4.7
}

#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR(void)
{
if (P1IFG & BIT7)
{
buzzer(0,10000);
}
}

If I don't include the highlighted line of code in my buzzer function. I can still hear some low level non-continuous noise coming out of buzzer after I push a button connected to P1.7. If I do include that line of code, basically disable TA1 interrupt, then that low level noise will go.

This is not a problem per se, but I am do want to understand why the above happens.

Thanks,

• The reason you need the highlighted line is that this:

TA1CTL |= MC_0;

doesn't turn off the timer. What you probably wanted was:

TA1CTL &= ~MC_3;

Unsolicited: P1_ISR needs to turn off BIT7 of P1IFG, else once you push the button your program will just cycle forever through P1_ISR and never do anything else.

• Thanks very much for response. It makes sense to me now.

01 | 00 actually does not do anything. I overlooked this matter.

Also thanks for the unsolicited tip.

**Attention** This is a public forum