带 msp430 的 RTC

发布于 2024-11-17 16:20:44 字数 1926 浏览 4 评论 0原文

我以前曾问过这个问题,但我想这次我可以问得更清楚一些。

以下是我的 RTC 测试代码。我正在将 msp430f5418 与 IAR EW 5 一起使用。

我的问题是一段时间后(我们测试了 15 分钟或更长时间),分钟中断比预期提前到来。

即,第一次,正好 60 秒后和 15 分钟后,分钟中断在第 45 秒发生。

为什么会这样呢?我们使用 TI 提供的库进行 RTC 寄存器操作。

谁能告诉我为什么会这样??

是代码的问题还是库使用不当或硬件本身的问题?

预先感谢...

#include <msp430.h>
#define RTC_VALID_READ_MAX_WAIT  500U
int main()
{
    WDTCTL = WDTPW + WDTHOLD;
    RTCCTL01 = RTCMODE + RTCTEVIE + RTCTEV_0;
    RTCCTL01 |= RTCHOLD;
    /* Calling the routines in the workaround assembly module supplied by TI */
    SetRTCYEAR (2011U);
    SetRTCMON (6U);
    SetRTCDOW (3U);
    SetRTCDAY (4U);
    SetRTCHOUR (23U);
    SetRTCMIN (0U);
    SetRTCSEC (0U);
    RTCCTL01 &= ~RTCHOLD;
    __enable_interrupt();
    while(1)
    {
    }
}

#pragma vector=RTC_VECTOR
__interrupt void handle_rtc_interrupt(void)
{
    switch(RTCIV)
    {
        case 2U:  /* RTC one second Ready Event for valid read */
        {
            int wait_counter = 0U;
            while (!(RTCCTL01&RTCRDY)) /* Wait for RTCRDY to go high, so read will be valid. */
            {
                wait_counter++;
                if (wait_counter > RTC_VALID_READ_MAX_WAIT)
                {
                    break;
                }
            }
            if (wait_counter<=RTC_VALID_READ_MAX_WAIT)
            {
                volatile int min = RTCMIN;
                volatile int sec = RTCSEC;
            }
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 &= ~RTCRDYIE;
            RTCCTL01 &= ~RTCHOLD;
            break;
        }
        case 4U:        /* RTC Minute Interval Event */
        {
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 |= RTCRDYIE;  /* Enable Ready Flag Interrupt */
            RTCCTL01 &= ~RTCHOLD;
            break;
        }
        default:
        {
            break;
        }
    }
}

哈里

I have asked this question before, but I think this time I can ask with some more clarity.

The below is my RTC Test code. I am using msp430f5418 with IAR EW 5.

My problem is after some time (we tested with 15 minutes and more) the minutes interrupt is coming earlier than expected.

ie, On first time, after exactly 60 seconds and after 15 minutes the minute interrupt comes on 45th seconds itself.

Why is it so? We are using the library provided by TI for RTC register manipulation.

Can anybody tell me why is it so??

Is it the problem with the code or with the improper usage of library or with the hardware itself??

Thanks in advance...

#include <msp430.h>
#define RTC_VALID_READ_MAX_WAIT  500U
int main()
{
    WDTCTL = WDTPW + WDTHOLD;
    RTCCTL01 = RTCMODE + RTCTEVIE + RTCTEV_0;
    RTCCTL01 |= RTCHOLD;
    /* Calling the routines in the workaround assembly module supplied by TI */
    SetRTCYEAR (2011U);
    SetRTCMON (6U);
    SetRTCDOW (3U);
    SetRTCDAY (4U);
    SetRTCHOUR (23U);
    SetRTCMIN (0U);
    SetRTCSEC (0U);
    RTCCTL01 &= ~RTCHOLD;
    __enable_interrupt();
    while(1)
    {
    }
}

#pragma vector=RTC_VECTOR
__interrupt void handle_rtc_interrupt(void)
{
    switch(RTCIV)
    {
        case 2U:  /* RTC one second Ready Event for valid read */
        {
            int wait_counter = 0U;
            while (!(RTCCTL01&RTCRDY)) /* Wait for RTCRDY to go high, so read will be valid. */
            {
                wait_counter++;
                if (wait_counter > RTC_VALID_READ_MAX_WAIT)
                {
                    break;
                }
            }
            if (wait_counter<=RTC_VALID_READ_MAX_WAIT)
            {
                volatile int min = RTCMIN;
                volatile int sec = RTCSEC;
            }
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 &= ~RTCRDYIE;
            RTCCTL01 &= ~RTCHOLD;
            break;
        }
        case 4U:        /* RTC Minute Interval Event */
        {
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 |= RTCRDYIE;  /* Enable Ready Flag Interrupt */
            RTCCTL01 &= ~RTCHOLD;
            break;
        }
        default:
        {
            break;
        }
    }
}

Hari

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身骄傲 2024-11-24 16:20:44

恐怕我无法帮助您调试代码,但我放弃了 5418 中的 RTC,因为我的硬件不断出现故障。那是在 2008 年,当时我有了原型和第一个生产芯片。我认为即使现在标准(非 A)级部件中的 RTC 错误也尚未得到完全解决。由于我必须在任何 5418 生产芯片(任何掩模版本/勘误表级别)上运行并且正在从 F2418 和 F149 处理器迁移,所以我已经有了一个软 RTC,然后又回到了那个。处理和功耗的开销是最小的。

I am afraid that I cannot help you with debugging the code but I gave up on the RTC in the 5418 as I was having continuous failures in the hardware. This was back in 2008 when I had prototype and first production silicon. I do not think that the RTC bugs have been fully worked out even now in the standard (non A) grade parts. As I have to run on any 5418 production silicon (any mask rev/errata level) and was migrating from the F2418 and F149 processor,s I already had a soft RTC and just went back to that. The overhead in processing and power consumption was minimal.

墨离汐 2024-11-24 16:20:44

绘制随时间变化的中断之间的间隔。让它冷却,重新启动,但用吹风机吹它并重复该情节。如果它发生变化,您的振荡器就会受到温度影响。

Plot the interval between interrupts over time. Let cool, restart, but run a hair drier at it and repeat the plot. If it changes you are getting a temperature effect on your oscillator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文