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.

RTC interrupting every second

Other Parts Discussed in Thread: MSP430F5510

I'm working on a wristwatch project and why not to use the RTC right?

So I'm using the driverlib to interface with the RTC, and just found out that the RTC interrupts minimally at minute. I want to capture one second intervals.

I know the alternative is TMR interrupts, but I'm not sure they will always be synchronized.

i.e.: Imagine I have 3 hands actuated by stepper motors, one for hours, one for minutes and one for seconds. If I use TMR_A 1-sec interrupts to move the seconds hand, can I use RTC_A to interrupt on minutes and hours? Is it guaranteed they will be always in sync?

  • Maybe you already did, in this forum you can find a lot of discussions about this issue, and what applies to milliseconds can be sometimes converted to seconds. A few of these discussions:

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/343384/1200486.aspx#1200486

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/340239/1191424.aspx#1191424

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/230142/1115410.aspx#1115410

    If one of these doesn’t answer your question try a new search, if still not come back here but tell us which MCU you want to work on.

  • >1-sec interrupts to move the seconds hand
    > can I use RTC_A to interrupt on minutes and hours? Is it guaranteed they will be always in sync?

    if you are using 1sec interrupt, why can you just not sec+1, if sec= 60 then sec=0 and min+1
    of course best would be to use pwm timers to advance the stepper motors without IRQ
    if you use 32k crystal>aclk> timerA0 it would be as accurate as any other wristwatch out there


    Only some msp430 have built-in hardware rtc, so what msp do you plan to use?

  • RTC_A in calendar mode has 2 interrupts which can be configured to occur once a second: RT1PSIFG and RTCRDYIFG. Driverlib may not provide all possible functionality for underlaying hardware, only the major and basic one. If you need more, you should program on module register level.

  • Hi Serge,

    Thanks for the tip. Since I'm using RTC in calendar mode, it seems these are don't care. From the user guide:

    "In real-time clock calendar mode, these bits are don't care for RT0PS and RT1PS. RT0PS clock output is automatically set to /256. RT1PS clock output is automatically set to /128."

    Which would set the interrupt interval at exactly 1 sec right?

    I've set RT1PSIE and I'm getting interrupts at a much higher frequency.

    I also tried following your advice (setting RTCPS0CTL and RTCPS1CTL) but it made no difference.

  • Thanks Leo,

    These gave me some more insight, but not enough to get it where I want.

    I was able to generate 1sec interrupts using TMR_A in addition to RTC. I thought it was overkill and maybe wrong. I think using the RTC would be the best approach.

    I'm using an MSP430F5510

    Here is my latest code. I've started using purely driverlib, but as I'm testing stuff, I'm gradually going directly to registers.

    void init_rtc()

    {

    //Setup Current Time for Calendar

    current_time.Seconds = 0x00;

    current_time.Minutes = 0x07;

    current_time.Hours = 0x20;

    current_time.DayOfWeek = RTC_SUN;

    current_time.DayOfMonth = 0x13;

    current_time.Month = RTC_JUL;

    current_time.Year = 0x2014;

     

    // Select XT1 as the source for the RTC

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN4+GPIO_PIN5);

    //Initialize LFXT1

    //UCS_LFXT1Start(UCS_XT1_DRIVE3, UCS_XCAP_3);

     

     

    //enable XT1

    P5SEL |= BIT4; //select P5.4 and P5.5 to XIN and XOUT

    UCSCTL6 &=

    ~(XT1OFF) | //bit0: turn XT1 on

    SMCLKOFF | //bit1: turn off SMCLK

    XCAP0 | XCAP1 | //bit2-3: 12pF load capacitance (XCAP=3)

    ~(XT1BYPASS) | //bit4: XT1 sourced externally from pin

    ~(XTS); //bit5: clear XTS to set low frequency (32.768 kHz)

     

    //set XT1 as source for ACLK (SELA in UCSCTL4 = 000)

    UCSCTL4 &= ~(SELA0) | ~(SELA1) | ~(SELA2);

     

     

     

     

     

    //Set initial time

    RTC_A_initCalendar(RTC_A_BASE, &current_time, RTC_A_FORMAT_BCD);

    RTCPS0CTL |= RT0PSDIV_7; /* RTC Prescale Timer 0 Clock Divide 32768/256 = 128 Hz */

    RTCPS1CTL |= RT1PSDIV_6; /* RTC Prescale Timer 1 Clock Divide 128/128 = 1 Hz */

    RTCPS1CTL |= RT1PSIE; /* RTC Prescale Timer 1 Interrupt Enable Flag */

    //RTC_A_clearInterrupt(RTC_A_BASE, RTCRDYIFG + RTCTEVIFG + RTCAIFG + RT0PSIFG);

    //RTC_A_enableInterrupt(RTC_A_BASE, RT1PSIE);

    //Start RTC Clock

    RTC_A_startClock(RTC_A_BASE);

     

    printf("RTC_A started\n");

    }

     

    // handler

    #pragma vector=RTC_VECTOR

    __interrupt void RTC_VECTOR_ISR(void)

    {

    switch(__even_in_range(RTCIV,16))

    {

    case 0: printf("0\n"); break; // No interrupt

    case 2: printf("2\n"); break; // RTCRDYIFG

    case 4: printf("4\n"); break; // RTCEVIFG

    case 6: printf("6\n"); break; // RTCAIFG

    case 8: break;

    case 10: // RT1PSIFG

    set_event(E_TICK);

    // Exit from LPM3 on RETI

    _BIC_SR_IRQ(LPM3_bits);

    break;

    case 12: printf("12\n"); break; // reserved

    case 14: printf("14\n"); break; // reserved

    case 16: printf("16\n"); break; // reserved

    default: break;

    }

    }

  • Hi Tony,

    I will need the RTC later to timestamp log entries.

    The stepper motors are custom lavet motors and wouldn't work with regular PWM.

    I'm using an MSP430F5510

    Cheers

  • Paulo Merloti said:

    Hi Serge,

    Thanks for the tip. Since I'm using RTC in calendar mode, it seems these are don't care. From the user guide:

    "In real-time clock calendar mode, these bits are don't care for RT0PS and RT1PS. RT0PS clock output is automatically set to /256. RT1PS clock output is automatically set to /128."

    Which would set the interrupt interval at exactly 1 sec right?

    I've set RT1PSIE and I'm getting interrupts at a much higher frequency.

    I also tried following your advice (setting RTCPS0CTL and RTCPS1CTL) but it made no difference.

    Hi Paulo,

    RT1PSIFG can generate interrupt intervals selectable by the RT1IP bits. In calendar mode, RT1PS is sourced with the output of RT0PS, which is 128 Hz (32768/256 Hz). Therefore, intervals of 64 Hz, 32 Hz, 16 Hz, 8 Hz, 4 Hz, 2 Hz, 1 Hz, or 0.5 Hz are possible. Setting the RT1PSIE bit enables the interrupt. 

    So set RT1IP bits of RTCPS1CTL register to 110b and you'll get 1Hz.

  • Just one more tidbit of information.

    I'm blinking an LED on RT1PSIE and I'm getting 64 Hz.

    I'm sure I'm setting some register wrong, but I don't know which one.

  • Paulo Merloti said:

    Just one more tidbit of information.

    I'm blinking an LED on RT1PSIE and I'm getting 64 Hz.

    I'm sure I'm setting some register wrong, but I don't know which one.

    That's because default settings for RT1IP is 000b, which gives 'Divide by 2'.  So 128/2 = 64Hz.

    So set RT1IP bits of RTCPS1CTL register to 110b and you'll get 1Hz.

  • Dammit!

    I thought RT1PSDIV was the register to configure that interval. I think now I understand that one is for generating the clock (internally configured in calendar mode) and the other is for generating interrupt intervals...

    Thanks for leading me to that conclusion. Please let me know if it's a wrong conclusion though.

    Cheers and Thanks Very Much

  • Your conclusion is correct.

    Though if you need to access the values of RTC (for example, read current RTC time/date for your timestamp) I would rather use RTCRDYIFG interrupt. It is triggered once per second as well, but also can prevent reading the time value during transition when it could give corrupted data. Read more about this interrupt in family data manual

  • For that I'm using driverlib's RTC_A_getCalendarTime. I checked their source code and they are polling RTCRDY before reading the date time values.

**Attention** This is a public forum