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.

MSP430F5438 RTC with milisecond precision

Other Parts Discussed in Thread: MSP430F5438

Hi everybody,

I've got an application running on MSP430F5438 where I need to record when events happen.

I've managed to get the RTC to work so I've got the time in up to the second, the problem is that I need to record the time in a finer resolution

(I'd like it to be 1 milisecond, but 10 milisecond will be OK).

Does anybody have any example code for this?

Thanks,

Nadav

  • No source code (belongs to my company), but a dexcription of an approach:

    Set up a timer that runs on a high frequency. The timer generates an interrutp every ms. This is every n timer ticks. In the timer interrupt function you increment a counter that counts milliseconds. Either one 32 bit counter (good for ~50 days) or a 16 bit ms counter and a separate seconds counter (32 bit, good for forever).

    Whenever a certain amount of time has passed (a few minutes), you compare the tiem that has passed on the timer-driven counte rwith the tiemr that has passe don teh RTC. If the tiemr was too fast, increment the number of timer ticks per interrupt, else decrement it. It will adjust the 'length' of a ms. This way, you have a continuous clock (the timer clock), with a resolution of 1ms and the long-time precision of the RTC.

  • Thanks for your answer,

    Does your high freq timer runs from an external crystal?

    I only have an 32KHz crystal connected to XT1 which means that if I want to use an high freq timer I can't go to LPM3 to save energy, right?

    The other problem I that I don't just need a ms timer, I need a ms counter that is syncronized with the RTC clock.

    i.e. the ms counter should advance from 999 to 0 at the same time the RTC updates the second.

    We would not want to have intervals where the RTC advanced the seconds but the ms timer is still at 999... (or that the ms counter already advanced from 999 to 0 but the RTC still haven't advanced the seconds...)

    Thanks,

    Nadav 

  • Nadav Popplewell said:
    Does your high freq timer runs from an external crystal?

    Normally yes. But as long as teh tiemr clock doesn't change too fast too much, any source is okay,a sthe algorithm will auto-adjust the interval time to the RTC.

    Nadav Popplewell said:
    if I want to use an high freq timer I can't go to LPM3 to save energy, right?

    The LPMs are just certain combinations of power-reducing actions. Like disabling SMCLK. Disabling SMCLK to save power while you need SMCLK makes no sense. However, you may disable ACLK (happens in LPM4) without disabling SMCLK (LPM3+4), creating your own LPMx. The only LPMs that are not doable in plain software are LPM0+1, as they stop MCLK and require the hardware to undo this. All other LPMs can be seen as a combination of LPM0/1 and additional settings. Which can be done separately too to save power and even without stopping the CPU at all.

    Nadav Popplewell said:
    The other problem I that I don't just need a ms timer, I need a ms counter that is syncronized with the RTC clock.

    That's difficult.
    The solution woudl be to use the RTC just for a long-time delay device and use teh already mentioned seconds counter as the timebase. The RTC is used only to tell that 'since last comparison, n seconds have passed' while the time is provided by your own counter that is of course snchronized to the ms counter, as it runs on the same interrupt.

    windows/linux system time is similar. The system time is plain timer based, but everty now and then the tiem is adjusted by an external NTP time server check.

**Attention** This is a public forum