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.

Timer B on MSP430

Hi,

I am working with CC2530 ZNP mini Kit which has MSP430 MCU. I have initiated Timer A to enable the interrupt for condition 'x'.

Condition 'x' is like it monitors the flow of liquid. If there is no obstruction in the flow of liquid, then it will generate an interrupt.

Below is the part of the code which I used to enable interrupt on Timer A. In this case, port 2 of MSP430 is used. 

clearLeds();
TACCTL0 = 0x5110;
TACTL = 0x01A2;
TAR = 0x0000;
//wakeupFlags |= WAKEUP_AFTER_TIMER;
while (1)
{
toggleLed(1);
printf("timer = %d, TACCR0 = %d \r\n ",TAR, TACCR0);
if(ovf_flag==1)
{
setLed(2);
printf("Sending Message %u\r\n", counter++);
afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 5);
handleReturnValue();
clearLeds();
ovf_flag = 0;
TACTL = 0x01A2;
TAR = 0x0000;
//TACTL |=(1<<TAIFG);
}
HAL_SLEEP();
//delayMs(1000);
}
}

void handleTimer_cap() //Will automatically wakeup timer
{
setLed(1);
TACCTL0 &=!(1<<CCIFG);
printf("$");
TAR = 0x0000; 
TACTL = 0x01A2;
TACCTL0 = 0x5110;
}

void handleTimer_ovf()
{

TACTL &=!(1<<TAIFG);
printf("@");
TAR=0x0000;
ovf_flag = 1;
//setLed(2); 
}

It is working fine.

Now, I want to enable the Timer B to enable interrupt for condition 'y' similar to 'x'. I have tried to use Port 4 of MSP430. But I couldn't succeed. Can you pls let me know how to proceed? Which pin of Port 4 should be selected for output?

Is it possible to initiate timers A and B at the same instant? If so, how should I do it? I checked the output on connector P2.2 for Timer A. Which pin should I use to monitor the interrupt generation for Timer A as well as Timer B simultaneously? I meant that Timer A and Timer B are working in parallel for different operations.

  • Shabana Shaik said:

    ...

    Now, I want to enable the Timer B to enable interrupt for condition 'y' similar to 'x'. I have tried to use Port 4 of MSP430. But I couldn't succeed. Can you pls let me know how to proceed? Which pin of Port 4 should be selected for output?

    ...

    What have you tried?  What did work, what did not work?

    TB[012] may be connected to P4.[012].

    H.

  • Shabana Shaik said:
    Is it possible to initiate timers A and B at the same instant?

    It is not easy, but doable. Since the CPU can only do one operation at a time, you cannot start or reset both timers at the very same moment. If they both run from a clock that is significantly slower than MCLK, you may wait for the timer clock tick having passed, then reset both timers before the next tick happens.

    If both run with a clock as fast (or nearly) as MCLK, you may generate soem assembly code that has carefully counted execution times, reset sone timer, then set the second to a value that corresponts to the number of clock cycles that is required to load and execute the second operation.

    A third way would to connect both timers external clocks to a clock output pin, reset the timers, then enable the clock output.

    However, only one ISR can be executed at a time, so if both timers trigger an itnerrupt, one of them is handled first, the other one later.

    But maybe that's not necessary at all. all tiemrs have multiple CCR modules. Each module runs synchronbously to the timer counter and can trigger an individual interrupt. Also, CCR0 has its own interrupt vector, all others share a second one.

  • Shabana Shaik said:

    ... Below is the part of the code which I used to enable interrupt on Timer A. In this case, port 2 of MSP430 is used.  ...

    In the code you posted, I did not see anything that enables interrupt nor anything that has to do with port 2.

    Shabana Shaik said:

    ... It is working fine.

    Now, I want to enable the Timer B ...

    I do not see how it could be wording fine. But if it did, then replacing all the occurences of "TA" with "TB" would be working fine too.

    By the way, not that it matters in your case, the statements: TACCTL0 &=!(1<<CCIFG); and TACTL &=!(1<<TAIFG);  in your code are somewhat peculiar. Did you really mean what you said? They are equivalent to TACCTL0 &= 0; and TACTL &= 0; respectively. You might have meant TACCTL0 &= ~CCIFG; and TACTL &= ~TAIFG; respectively.

**Attention** This is a public forum