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.

CCS/MSP430F6638: MSP430F6638 RTC and Timer

Part Number: MSP430F6638


Tool/software: Code Composer Studio

Hello,

I designed a system (collecting some data from sensors) based on the MSP430F6638. Basically my system has to start automatically a new measurement each 15 minutes. So, I would like my program after the end of a measurement to wait 15 minutes and then start automatically a new measurement. What peripheral should I use between the RTC and the Timer to achieve this functionality ? I mean I checked the MSP430f6638 user guide but I couldn't find for the RTC (p569) this sepcific functionality in the rtc alarm function chapter. And which interrupts seem to be important for this application (there is lot of interrupt for rtc and timer) ? I am a little bit lost about how to achieve this and I don't really know which peripheral is better for my application between a timer and rtc. I hope that all is clear.

Thank you.

Best regards,

Mike

  • A standard Timer (A/B), even with the maximum clock dividers, won't give you nearly 15 minutes, so the RTC would be the indicated choice.

    The RTC_B doesn't have a "counter" (delta time) mode, so you need to set a calendar alarm, which isn't a great fit but it will do. Consider using the "minute alarm" -- at each alarm add 15 (modulo 60) to the minute-alarm register (and set the alarm-enable bit).

  • Hi Bruce,

    Thank you for your response. The MSP430F6638 has also the RTC_A. Does it have a "counter" mode (as you named it ) ? I mean would it be better with RTC_A or RTC_B ? And i'm sorry I didn't really understand the principle of what you proposed as a possible solution. I didn't get it with the modulo 60 and the minute alarm mode. Can you give more explanations ? Because in the user guide for the rtc alarm function there are examples p597 about how to set an alarm at a specific hour, day, month...etc and there is no example to set an alarm each "x" minutes. 

    Thank you very much.

    Regards,

    Mike

  • I don't see any mention of RTC_A in the data sheet (SLAS566F), so I expect it isn't there. It would be unusual for the device to have both. RTC_A does have a counter mode. [Ref User Guide Sec 22.1]

    User Guide (SLAU208Q) Sec 23.2.2 Example 1 talks about using RTCAMIN to trigger an alarm at 15 minutes past each hour. If, as part of processing that alarm (interrupt), you were to increment RTCAMIN to 30 (then ->45->00->15), you would get an alarm every 15 minutes. It's a but clumsy but not difficult. (Make sure your arithmetic doesn't accidentally clear the AE bit.)

  • Hi,

    Please see the datasheet F6638 only has RTC_B.

     You can refer to this example. It use RTC to trigger LED every second. 

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430F66x Demo - RTC_B in real time clock mode
    //
    //   Description: The RTC_B module is used to set the time, start RTC operation,
    //   and read the time from the respective RTC registers. Software will set the
    //   original time to 11:59:45 am on Friday October 7, 2011. Then the RTC will
    //   be activated through software, and the time will be read out once every 
    //   second. The proper handling of the RTC interrupt is shown as well.
    //
    //  //* An external watch crystal on XIN XOUT is required for ACLK *//	
    //   ACLK = 32.768kHz, MCLK = SMCLK = default DCO~1MHz
    //
    //                MSP430F66xx
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 | 32kHz
    //          --|RST          XOUT|-
    //            |                 |
    //            |             P1.0|--> LED
    //
    //   F. Chen
    //   Texas Instruments Inc.
    //   December 2012
    //   Built with IAR Embedded Workbench V5.51.1 & Code Composer Studio V5.2.1
    //******************************************************************************
    
    #include <msp430.h>
    
    unsigned int Seconds;
    unsigned int Minutes;
    unsigned int Hours;
    
    int main (void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      
      while(BAKCTL & LOCKBAK)                    // Unlock XT1 pins for operation
         BAKCTL &= ~(LOCKBAK);
      
      UCSCTL6 &= ~(XT1OFF);                     // XT1 On
      UCSCTL6 |= XCAP_3;                        // Internal load cap
      
      // Loop until XT1,XT2 & DCO stabilizes - In this case loop until XT1 and DCo settle
      do
      {
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                                // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
      P1DIR |= BIT0;						    // P1.0 Output
      P1OUT &= ~BIT0;                           // Clear LED to start
    
      // Configure RTC_B
      RTCCTL01 |= RTCRDYIE + RTCBCD + RTCHOLD;  // BCD mode, RTC hold, enable RTC read ready interrupt
    
      RTCYEAR = 0x2011;                         // Year = 0x2011
      RTCMON = 0x10;                            // Month = 0x10 = October
      RTCDAY = 0x07;                            // Day = 0x07 = 7th
      RTCDOW = 0x05;                            // Day of week = 0x05 = Friday
      RTCHOUR = 0x11;                           // Hour = 0x11
      RTCMIN = 0x59;                            // Minute = 0x59
      RTCSEC = 0x45;                            // Seconds = 0x45
    
      RTCCTL01 &= ~(RTCHOLD);                   // Start RTC calendar mode
    
      __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 mode with interrupts
                                                // enabled
      __no_operation();
    
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_VECTOR
    __interrupt void RTCISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) RTCISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    
     while(BAKCTL & LOCKBAK)                    // Unlock backup system
            BAKCTL &= ~(LOCKBAK); 
    
      switch(__even_in_range(RTCIV,14))
      {
      case  0: break;                           // Vector  0:  No interrupt
      case  2:                                  // Vector  2:  RTCRDYIFG
        P1OUT ^= BIT0;                          // Toggle LED every second
        Seconds = RTCSEC;                       // Read all associated time registers
        Minutes = RTCMIN;
        Hours = RTCHOUR;
        break;
      case  4: break;                           // Vector  4:  RTCEVIFG
      case  6: break;                           // Vector  6:  RTCAIFG
      case  8: break;                           // Vector  8:  RT0PSIFG
      case 10: break;                           // Vector 10:  RT1PSIFG
      case 12: break;                           // Vector 12:  RTCOFIFG
      case 14: break;                           // Vector 14:  Reserved
      default: break;
      }
    }
    

    Eason

**Attention** This is a public forum