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.

MSP430F2616: Timer A interrupt is working only for 102 counts and then it stops interrupting the processor

Part Number: MSP430F2616

Port 1 bit 7 is used for checking the interrupt.

#include <msp430F2616.h>
#define DR P5OUT = P5OUT | BIT7 // define RS high
#define CWR P5OUT = P5OUT & (~BIT7) // define RS low
#define READ P5OUT = P5OUT | BIT5 // define Read signal R/W = 1 for reading
#define WRITE P5OUT = P5OUT & (~BIT5) // define Write signal R/W = 0 for writing
#define ENABLE_HIGH P5OUT = P5OUT | BIT6 // define Enable high signal
#define ENABLE_LOW P5OUT = P5OUT & (~BIT6) // define Enable Low signal
void check_busy(void);
void data_read(void);
void delay(unsigned int wt);
void init(void);
void init_lcd(void);
void wr_lcd_cw(unsigned char lcd_cmd);
void wr_lcd_dw(unsigned char wr_lcd_dw);
void lcd_msg(unsigned char *ch);
volatile unsigned int a=0,b=0,c=0,d=0,e,f,sec1=2,AS;

//__interrupt void Timer_A (void);
//PIN R/W =
/*
* main.c
*/
void count_increment(void);

unsigned char array[10]={"0123456789"};


int main(void) {

volatile unsigned int i;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
init();
init_lcd();

delay(1000);
P1OUT &= ~BIT7;

wr_lcd_cw(0x80);
lcd_msg(( unsigned char *)"UP count");

while (1)
{
for(a=0;a<10;a++)
{
wr_lcd_cw(0xC0);
wr_lcd_dw(array[a]);
for(b=0;b<10;b++)
{
wr_lcd_cw(0xC1);
wr_lcd_dw(array[b]);
for(c=0;c<10;c++)
{
wr_lcd_cw(0xc2);
wr_lcd_dw(array[c]);
for(d=0;d<10;d++)
{
wr_lcd_cw(0xc3);
wr_lcd_dw(array[d]);
P1OUT ^= BIT5|BIT6;
delay(1000); // Toggle P1.0 using exclusive-OR
//delay(1000) //while(~(TAIV));1 second delay
}
}
}
}


if(AS)
{
AS=0;
// count_increment();

}
}
}
void count_increment(void)
{

/*if(array[d]<10)
{
d++;
wr_lcd_cw(0xc3);
wr_lcd_dw(array[d]);
}
else if(array[c]<10)
{
c++;
wr_lcd_cw(0xc2);
wr_lcd_dw(array[c]);
}
else if(array[b]<10)
{
b++;
wr_lcd_cw(0xc1);
wr_lcd_dw(array[b]);
}
else if(array[a]<10)
{
a++;
wr_lcd_cw(0xc0);
wr_lcd_dw(array[a]);
}

* }*/

P1OUT ^= BIT7;
sec1 = 2;
}

void delay(unsigned int wt)
{
unsigned int k;
volatile unsigned int i ;
for(k=0;k <= wt ;k++)
{
//for( i = 0 ; i <= 800 ; i++ );
_delay_cycles(16000);

}
}

void lcd_msg(unsigned char *ch)
{
while(*ch !='\0')
{
wr_lcd_dw(*ch);
ch++;
}
}
void wr_lcd_cw(unsigned char lcd_cmd){
check_busy();
P4OUT=lcd_cmd;
CWR;
WRITE;
ENABLE_HIGH;//EN=1
delay(3);
ENABLE_LOW;//EN=0
}

void wr_lcd_dw(unsigned char lcd_data){
check_busy();
P4OUT=lcd_data;
DR;
WRITE;
ENABLE_HIGH;//EN=1
delay(3);
ENABLE_LOW;//EN=0
}

void init_lcd(void)
{
wr_lcd_cw(0x38);delay(10);//LCD in 8 bit mode
wr_lcd_cw(0x0e);delay(10);//LCD in 8 bit mode
wr_lcd_cw(0x06);delay(10);//LCD in 8 bit mode
wr_lcd_cw(0x01);delay(10);//LCD in 8 bit mode

//lcd_content(0x02);//return to home location

}

void init(void)
{
DCOCTL = 0x60;
BCSCTL1 = 0xFF;
BCSCTL2 = 0x00;
BCSCTL3 = 0x20;
IFG1=0X00;
IFG2=0X00;

TACTL = 0x01D0;
TACCTL0 = CCIE; // CCR0 interrupt enabled
TACCR0 = 16000;

P1SEL=0;
P5SEL=0;
P4SEL=0;

P1DIR=0xff;
P4DIR=0xff;
P5DIR=0xff;
//INITIALISE UNUSED PORTS TO SAVE POWER
P2DIR=0XFF;
P3DIR=0XFF;
P6DIR=0XFF;
P7DIR=0XFF;
P8DIR=0XFF;
P2OUT=0X00;
P3OUT=0X00;
P6OUT=0X00;
P7OUT=0X00;
P8OUT=0X00;

P1DIR |= BIT5|BIT6; // Set P4 bits 5 and 6 to output direction
P4DIR = 0XFF; // Set Port 4 as output
P5DIR = 0XFF; // Set Port 5 as output
P4OUT = 0X00;
P5OUT = 0X00;
__bis_SR_register(GIE);
}
void check_busy(void)
{
P4DIR &= ~(BIT7); // make P2.3 as input
data_read();
while((P4IN & BIT7)==1)
{
data_read();
}
P4DIR |= BIT7; // make P2.3 as output
}

void data_read(void)
{
CWR;
READ;
ENABLE_LOW;
delay(2);
ENABLE_HIGH;
}
// Timer B0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)

{
sec1--;
//P1OUT^=BIT7;
if(sec1==0)
{
count_increment();
}
AS=1;
//P1OUT ^= BIT5|BIT6|BIT7; // Toggle P1.0
TACCR0 += 16000; // Add Offset to CCR0
//TACTL &= ~TAIFG;
}

  • >DCOCTL = 0x60;
    >BCSCTL1 = 0xFF;
    >BCSCTL2 = 0x00;
    >BCSCTL3 = 0x20;

    These settings seem problematic. 

    1) As I squint at the DCO table (SLAS541K p.42) you may be overclocking.

    2) You're setting ACLK, which drives TimerA, to an external high-frequency crystal. Since you're running S/MCLK from the DCO, my guess is that the crystal isn't there, and you're encountering a clock fault which stops the timer.

    Is there a reason you're not using CALDCO_16MHZ and CALBC1_16MHZ?

    Also, I expect that coding using the bit names will make this easier to untangle.

    Unsolicited:

    >while((P4IN & BIT7)==1)

    This condition is always false. Try:

    >while((P4IN & BIT7))

**Attention** This is a public forum