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.

MSP430F4784: one second delay using Timer

Part Number: MSP430F4784


Hi,

    I'm currently using MSP430F4784 controller.

In this I want to make a N number of delays (maximum 10sec delay only).

I'm able to achieve the required delay I want but while the program is running the execution stays at particular while loop in delayMS function which I included below.

But this is happening abruptly and continues for 3 to 4 times in a sequence. what could be causing this issue.

Please kindly help me with this.

volatile unsigned int k=0;
volatile unsigned int h=0;
volatile unsigned int l=0;

void tim(void)
{
    TACTL |= MC_0;
     TACTL |= TACLR;
      TACTL = TASSEL_1 + ID_0;                  // SMCLK, continuous mode
      TA0CCTL0 = CCIE;
      TA0CCR0  = 32768;

}

void delayMS(int x)
{
    TACTL |= MC_2;
    k=0;
    h= x;
    while(!l);

    l=0;
    TACTL |= MC_0;
}


int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	P9DIR |= BIT5;

	tim();
	
	while(1)
	{
	    P9OUT ^= BIT5;
	    delayMS(2);
	  }
	 }
	 
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0( void )
{
    TA0CCTL0 &= ~CCIFG;
                        
  k++;
    if(k == h)
    {
       k=0;
       l=1;
    }
}

	 
	 

**Attention** This is a public forum