Part Number: MSP430FR5994
I wanted to make a delay using TimerA with SMCLK = 16 MHz.
The following code works and gives the requested delay, approximately, where the argument of the function is the requested delay in microseconds:
void Delayus(unsigned int delayamt)
{
// Delay is 0-65535 usec; already initialized to use SMCLK, divide by 16 so timer increments once/usec; upon reaching delayamt, one interrupt is given and the delay is over
TA0CCR0 = delayamt; // Interrupt when up-count to this value
TA0CTL |= (MC_1 | TACLR);
__bis_SR_register(LPM0_bits | GIE); // Go to sleep. Timer0 ISR will wake us up when proper time has elapsed
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
TA0CTL |= MC_0; // Stop Timer0
__bic_SR_register_on_exit(LPM0_bits); // Wakeup from LPM0 and continue after the Delayus function
}
Having achieved success, I thought that I would expand on it to achieve large, of the order of seconds, delays. It does not work.... the CPU goes to sleep forever.
void Delaysec(unsigned int dela) // Delay is 0-65.535 msec
{
unsigned long i, delas;
delas = 20*dela; // 1 sec = 20*50,000 usec
for (i=0; i<delas; i++) Delayus(50000);
}
In the main routine, I had already disabled the watchdog.
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog
Any ideas why this fails?