Question

I am using MSP430F5418 with IAR EW 5.10. I want to use Timer B in up mode.

I want to use two interrupts. TimerB0(1 ms) and TimerB1(1 second).

My Configuration is

TBCTL = MC__UP + TBSSEL__ACLK + TBCLR;
TB0CCTL0 = CCIE;
TB0CCR0 = 32;

TB0CCTL1 = CCIE;
TB0CCR1 = 32768;

On the ISR I just toggled two pins. But only the pin for TB0CCR0 is toggling. My Pin Configurations are correct. Can anyone tell me why??

Was it helpful?

Solution

I suppose your problem is the timer period.
MC__UP Up mode: Timer counts up to TBxCL0

So your timer TBxR will reset to 0 when it reaches TBxCL0 which seems to be the value TB0CCR0.

So it can never reach the value of 32768.

You could switch TB0CCR0 with TB0CCR1, so your period will be 1 second.
And to get your 1ms interrupt you need to increment your TB0CCR1 each time.

INTERRUPT ISR_1MS()
{
  TB0CCR1 = (TB0CCR1 + 32) & 0x7FFF;
}

But normally you don't need a second timer for a second intervall.
You could simply count 1000 times your 1ms intervall.

INTERRUPT ISR_1MS()
{
  ms_count++;
  if (ms_count >= 1000)
  {
    ms_count=0;
    // Do your second stuff
  }
}

And if you need more and different intervalls, you could change to another model.
To a system clock time and check only against this time.

volatile unsigned int absolute_time=0;

INTERRUPT ISR_1MS()
{
  absolute_time++;
}

unsigned int systime_now(void)
{
    unsigned int result;
    di();
    result = absolute_time;
    ei();
    return result;
}

uint8_t systime_reached(unsigned int timeAt)
{
   uint8_t result;
   result = (systime_now() - timeAt ) < 0x1000;
   return result;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top