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.

Creation of a delay of one hour

Part Number: MSP430FR2155


Hello TI Experts!

I am working with MSP430FR2155 and i want to do some calculations for every on hour and update the values. I want to create a timer interrupt that can be used to do these calculations. Or is there any function that could create a delay for an hour?

Also I would like to know what maximum delay can be achieved using the timer interrupts and the necessary settings for that.

How do i go about this?

Any help is appreciated. 

Thanks in advance!

  • It depends on your clock. But you can get almost any delay by using shorter delays and just wait for N of them to wait an hour. For example, if your delay is 1 second, in every interrupt you increment a counter. Once you get to 3600 you perform your action and set the counter back to 0.

  • Hello,

    Keith brings up a good point.  To get an hour delay, you probably need to wake up more often and implement a counter.  I'd probably recommend using the RTC for this.  You can easilly configure the RTC timer to wake every second or every minute, and then count those up for your longer time periods.  

    Good luck!

    JD

  • Hey Keith

    Thank you for your suggestion. I am unfamiliar with the concept of interrupts. Is there any example code for the logic that you've suggested?

  • Hey JD,

    Again I am pretty new to RTC as well, so is there any example code for the function that you have mentioned or any thread that I could refer to? 

    I just got to know about the RTC yesterday and i searched through the TI's resource explorer for the examples of the same. But I did not find any.

  • There are plenty of examples in resource explorer. Here is one (msp430fr235X_lpm4_5_02.c) that uses the RTC to generate an interrupt every second (It requires a 32K crystal):

    //******************************************************************************
    //   MSP430FR235x Demo - LPM3.5, device enter LPM3.5 and toggles P1.0 with
    //                       RTC interrupt handling every 1s
    //
    //
    //   Description: Device enter LPM3.5 after configuring the RTC. The RTC wakes
    //   the device up from LPM3.5 every second and toggles P1.0.
    //   It also stores the state of P0OUT in the Backup RAM Registers.
    //
    //   ACLK = XT1 = 32kHz, MCLK = SMCLK = default DCODIV = ~1MHz.
    //
    //            MSP430FR2355
    //         -----------------
    //     /|\|                 |
    //      | |                 |
    //      | |        XIN(P2.7)|--
    //      --|RST              |  ~32768Hz
    //        |       XOUT(P2.6)|--
    //        |                 |
    //        |             P1.0|-->LED
    //
    //   Cash Hao
    //   Texas Instruments Inc.
    //   November 2016
    //   Built with IAR Embedded Workbench v6.50.0 & Code Composer Studio v6.2.0
    //******************************************************************************
    #include <msp430.h>
    
    void initGpio(void);
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop WDT
    
        initGpio();                             // Configure GPIO
    
        // Initialize XT1 32kHz crystal
        P2SEL1 |= BIT6 | BIT7;                  // P2.6~P2.7: crystal pins
        do
        {
            CSCTL7 &= ~(XT1OFFG | DCOFFG);      // Clear XT1 and DCO fault flag
            SFRIFG1 &= ~OFIFG;
        } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
    
        // First determine whether we are coming out of an LPMx.5 or a regular RESET.
        if (SYSRSTIV == SYSRSTIV_LPM5WU)        // When woken up from LPM3.5, reinit
        {
            // If MCU wakes up from LPM3.5, re-init and then return to LPM3.5 again.
    
            // Restore P1OUT value from backup RAM memory, keep P1OUT after LPMx.5 reset
            P1OUT = *(unsigned int *)BKMEM_BASE;
    
            __enable_interrupt();               // The RTC interrupt should trigger now...
        }
        else
        {
            // Device powered up from a cold start.
            // It configures the device and puts the device into LPM3.5
    
            // Configure backup memory
            *(unsigned int *)BKMEM_BASE = 0;
    
            // Configure RTC
            // Interrupt and reset happen every 1024/32768 * 32 = 1 sec.
            RTCMOD = 32-1;
            RTCCTL = RTCSS__XT1CLK | RTCSR |RTCPS__1024;
            RTCCTL |= RTCIE;
    
            // Store P1OUT value in backup memory register before enter LPM3.5
            *(unsigned int *)BKMEM_BASE = P1OUT;
        }
    
        // Enter LPM3.5 mode with interrupts enabled. Note that this operation does
        // not return. The LPM3.5 will exit through a RESET event, resulting in a
        // re-start of the code.
        PMMCTL0_H = PMMPW_H;                    // Open PMM Registers for write
        PMMCTL0_L |= PMMREGOFF;                 // and set PMMREGOFF
        __bis_SR_register(LPM3_bits | GIE);
        __no_operation();
    
        return 0;
    }
    
    void initGpio()
    {
        P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF; P5DIR = 0xFF; P6DIR = 0xFF;
        P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF; P4REN = 0xFF; P5REN = 0xFF; P6REN = 0xFF;
        P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00; P5OUT = 0x00; P6OUT = 0x00;
    
        // Disable the GPIO power-on default high-impedance mode
        // to activate previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = RTC_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(RTCIV, RTCIV_RTCIF))
        {
            case RTCIV_NONE : break;            // No interrupt pending
            case RTCIV_RTCIF:                   // RTC Overflow
                // Toggle LED on P1.0
                P1OUT ^= BIT0;
    
                // Store P1OUT value in backup memory register
                *(unsigned int *)BKMEM_BASE = P1OUT;
                break;
            default:          break;
        }
    }
    

  • Oh alright!

    Thank you Keith. Will check with the code once

**Attention** This is a public forum