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.

MSP430FR2111: timer help for MSP430

Part Number: MSP430FR2111

Hi all,

Can someone please guide me on how to use a timer my situation?

As I understand that using __delay_cycles(15000); is not good solution for power consumption.

I do not want to use external cyrstal and prefer the lowest power internal oscillator, timing precision is not critical at all. 

~1/4 second to 2 seconds of adjustable timer will be great.

Thanks,

Jay

#include <msp430.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;
    P1DIR = 0xFF;
    P1OUT = 0x00;
    P2DIR = 0xFF;
    P2OUT = 0x00;

    P1OUT &= ~BIT0;
    P1DIR |= BIT0;

    P1OUT |= BIT3;
    P1REN |= BIT3;
    P1IES |= BIT3;
    P1IE |= BIT3;

    PM5CTL0 &= ~LOCKLPM5;
    P1IFG &= ~BIT3;
    
    while(1)
    {
        __bis_SR_register(LPM4_bits | GIE);
            P1OUT |= BIT0;                   
            __delay_cycles(15000);            
            P1OUT &= ~BIT0;
    }
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    P1IFG &= ~BIT3;
    __bic_SR_register_on_exit(LPM4_bits);

}

  • It's not clear to me what it is you want to do with the timer. Here's one possible scheme -- written for the G2553, but should be fairly easily to adapt:

    https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/718133/2648381

    You may not get much out of LPM4, since on the FR2111 no clocks run in LPM4. [Ref Data Sheet (SLASE78C) Table 6-1] In LPM3, you can use VLOCLK for the RTC or the WDT [Ref Data Sheet Table 6-7], either of which can be used for timing in an analogous manner. The VLOCLK, as you mentioned, isn't very accurate, but it's cheap, and the REFO on the FR21 series is moderately expensive (15-20uA).

    [Edit: I guess I should have searched a little further. The "NOTE" in data sheet Sec 6.3 says you can use VLOCLK (for WDT or RTC) in LPM4. And the Table in Sec 5.7 even has entries for those possibilities. I suggest you try it before you "bet your project" on it.]

    ----------

    Unsolicited: I recommend you "P1DIR &= ~BIT3;", or each time you push the button you'll dump a whole lot of current to GND.

    ----------

    [Edit: Moved Edit: to be more clear.]

  • Hi Bruce,

    Thanks very much for the link. I am still debating whether it is worth the effort of using timer and interrupt or just keep using __delay_cycles(15000);

    The whole idea was to save power by not using _delay_cycles() but it seems like I am not going to save much power other than make code more complex unnecessary for such a simple delay.

    Per the link, a free-running timer is also a good idea that I can used in future for various tasks if need be. However, doesn't look it's worth the effort as of now, if there is not significant power saved.

    Also, thanks for a great suggestion to change the port direction. Are you suggesting to put the line as below? I have a hal sensor connected to this pin and when interrupt is called I should change direction as below?

    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
        P1IFG &= ~BIT3;
    P1DIR &= ~BIT3; //change the pin direction here to save current drain to ground? __bic_SR_register_on_exit(LPM4_bits); }

  • I was echoing the suggestion from over here:

    https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/955490

    You know how your Hall sensor works better than I. But if it tries to drive the line low, and you're driving the line high, that's a bus conflict.

    I recommend you switch it to an input (by clearing P1DIR:BIT3) as early as you can. Ideally, don't set it to output at all but it doesn't matter until the other end drives low.

**Attention** This is a public forum