RTC interrupt?

05 Jan 2010 . Edited: 05 Jan 2010

Can an interrupt be attached to an RTC tick?

Timeout and ticker classes are good, but I want to have an ISR called upon each new RTC value, so date-related calculations can be made (like DST adjust).

My sense is that timers are pretty expensive (power-wise) to run, and given 1 second period of RTC, it is 1000x savings on ISR calls. Also, if MBED is ever made to sleep (in the future rev?), RTC ISR should be called once a second even from the sleep.

05 Jan 2010 . Edited: 05 Jan 2010

Hi Illy,

Ilya I wrote:
Can an interrupt be attached to an RTC tick?

Yep, the chip supports interrupts on RTC. Take a look at http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h#L440 for the RTC register structure. The static handler you'd want to implement would be void RTC_IRQHandler().

If I remember rightly, it is a case of setting a match mask and then enabling interrupts.

Ilya I wrote:
My sense is that timers are pretty expensive (power-wise) to run, and given 1 second period of RTC, it is 1000x savings on ISR calls

If you create a Ticker with a tick of 1 second, you'll only get 1 interrupt a second.

Simon

06 Jan 2010

Thanks Simon, I will take a look at RTC registers. I actually need something like alarm clock service, that would call my handler at preset time when it is reached by the RTC. Is there any chance of implementing it in the mbed library in the future?

Meanwhile I am using a ticker.attach(..., 1.0) with an "if(time(NULL)>alarm) {...}" in the callback and it works fine for what I am trying to do.

Some of the concerns of using a ticker or a timeout are:

  • not being able to make mbed sleep and thus using extra energy to run it (RTC timer would be way more efficient), which can be a big drain if running from a battery. It is OK for a quick proto, but will be a real concern for productizing it.
  • possible skew of RTC value. If handler was running from RTC tick interrupt, it would be guaranteed to have stable RTC value for almost 1 second. If it runs from another timer, RTC value can change in the middle of the handler code. It can be diminished by careful code guarding, but I rather have a simpler code.

 

05 Nov 2010

Dear Ilya,

di have finish the methode? I'm looking for this function..

02 Dec 2010 . Edited: 03 Dec 2010

doesnt work

this interrupt is stucked after calling by the RTC chip

used RTC example from nxp

http://ics.nxp.com/support/documents/microcontrollers/?type=software

09 Apr 2012

sorry for reviving this old thread. wondering if anyone successfully configured the RTC interrupt? specifically i'm interested in a 1 second heartbeat from the RTC... Tnx

09 Apr 2012

use a 0.7 sec timer and read the RTC clock, that can give you a 1 second heartbeat

09 Apr 2012

tnx bert. would like to make the fix at a level closer to the hardware if possible. i think that the "RTC_CntIncrIntConfig" needs to be manipulated such that a specified isr is called on a 1 second interval. this would be my 1st attempt at tinkering below the library level and i could use some pointers... tnx in advance...

10 Apr 2012

you might want to explore the RIT (repetitive interrupt timer) first, easier to setup than the RTC if all you need is a system tick interrupt every now and then. Of course, you'll need to have access to the LPC17XX user manual to do all the low level stuff

#define LOW_PR      31

extern "C" void RIT_IRQHandler()
{
    //clear flag
    LPC_RIT->RICTRL |= (1<<0);
}


void rit_init(void)
{
    //initialize RIT timer
    LPC_SC->PCONP |= (1<<16);             //power up RIT clock
    LPC_SC->PCLKSEL1 |= (3<<26);          //run RIT clock by 12MHz (prescale by 8)
    LPC_RIT->RICOUNTER = 0;               //set counter to zero
    LPC_RIT->RICOMPVAL = 11999999;        //tick every second
    LPC_RIT->RICTRL |= (1<<1) | (1<<3);   //enable timer clear on match

    NVIC_SetPriority(RIT_IRQn, LOW_PR);
    NVIC_EnableIRQ(RIT_IRQn);
}

10 Apr 2012

tnx for the reply Herson (and the example). thinking a bit more about this, I would like simply to implement a 24hr clock (hrs, min). while the RIT gives me a configurable heartbeat, I would have to write code for the clock proper. I think thats all nicely done within the RTC. an every 1 min interrupt from the rtc seems to best fit the bill. enabling "RTC_CntIncrIntConfig" gets me where i'd like to be i believe. will the manual give me the fine points on this? eg powering up RTC (see that in your example above), enabling irq and method for attaching an isr? tnx VERY much for getting me started on this...

garyb

10 Apr 2012

the user manual gives you the nitty gritty details of the peripherals, how they operate, their limitations, register addresses and the good stuff but doesn't include anything related to the peripheral library usage. those would come from the manufacturer's extensive application manuals.

if you have the time, go with the user manual/datasheet and read up on how to manually power up the peripherals. that's how i learn my stuff and believe me, it would help you a lot understanding the ARM core and the special features that comes with it. whatever you learn from this exercise would transfer to just about any ARM microcontroller, no library needed.

13 May 2012

Herson, tnx for the help. I have the RTC interrupt working quite nicely now thanks to your aid. You were spot on correct re: prowling thru the manual (and deep into the nxp app notes). A bit of a slog but payed off in understanding...