CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24F, RTC Alarm

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andresteff



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

PIC24F, RTC Alarm
PostPosted: Sat Mar 21, 2020 6:14 am     Reply with quote

Hello,

The rtc alarm function on the PIC24F32KA304 does not so work.
The RTC itself works fine.

The alarm should be 2 minutes after start, but the interrupt comes after one minute!
Code:

#INT_RTC
void  RTC_isr(void)
{
      LED_AN;
}


// Variable time:
      rtc_time_t     write_clock, read_clock;

// Variable alarm:
       rtc_time_t    write_alarm, read_alarm;


// RTC ON
      setup_rtc(RTC_ENABLE, 0);
   

// time:
      write_clock.tm_year = 20;
      write_clock.tm_mon  = 03;
      write_clock.tm_mday = 19;
      write_clock.tm_wday = 04;
      write_clock.tm_hour = 22;
      write_clock.tm_min  = 00;
      write_clock.tm_sec  = 00;
     
      rtc_write(&write_clock);



// Alarm:
      setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_MINUTE, 0);
     
      write_alarm.tm_year = 20;
      write_alarm.tm_mon  = 03;
      write_alarm.tm_mday = 19;
      write_alarm.tm_wday = 04;
      write_alarm.tm_hour = 22;
      write_alarm.tm_min  = 02;
      write_alarm.tm_sec  = 00;
     
      rtc_alarm_write(&write_alarm);

// Interrupts: INT_RTC
   clear_interrupt(INT_RTC);
   enable_interrupts(INT_RTC);
   enable_interrupts(GLOBAL);

    while(1){}
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 8:12 am     Reply with quote

Use the 'search' option for the forum, there are some previous messages about how it works.....May not be the same PIC, but similar internal RTC peripheral.
jeremiah



Joined: 20 Jul 2010
Posts: 1314

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 10:41 am     Reply with quote

Keep in mind for that chip if you are using the internal low power RC for the RTC (don't know if you are or not), that in that family of chips most of them have a really wide tolerance on the oscillator (one of a similar chip from that family had plus or minus 15% tolerance.

I don't know if that is playing a part or not, but something to keep in the back of your mind.

Can you provide a complete small example that compiles and reproduces the issue so others could try it out and see what they come up with? Fragments don't help if something seemingly unrelated is causing the problem.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 12:55 pm     Reply with quote

Problem will be the alarm mask. This is totally 'non intuitive'.
Try with RTC_ALARM_YEAR. It shoukld then alarm when everything
below this mask value matches. With minute selected, it'll alarm
when the seconds match.... Not what you want.
andresteff



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 5:54 am     Reply with quote

Thanks for the infos, it's goes !

The key is the correct assignment of the alarm mask to the time variables, on page 197.

As Ttelmah has written, it's 'non intuitive'.
An example on the datasheet would be a good idea.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 8:45 am     Reply with quote

Yes the first time I met this I spent the day performing 'wall, head impact
technology testing'....

Glad I could point to the problem. Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 9:14 am     Reply with quote

re: Yes the first time I met this I spent the day performing 'wall, head impact
technology testing'....

that's not too bad..
I remember spending a WEEK of that 'testing' when cutting code between two systems...one used 'LF,CR' formatting the other 'CR,LF'......for 'end of line'...

bad enough around then 9 pin 'RS23' came along and TXD became RXD and vice versa..

sigh... some days I miss the good old days.....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group