View previous topic :: View next topic |
Author |
Message |
andresteff
Joined: 21 Mar 2020 Posts: 44
|
PIC24F, RTC Alarm |
Posted: Sat Mar 21, 2020 6:14 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Mar 21, 2020 8:12 am |
|
|
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: 1346
|
|
Posted: Sat Mar 21, 2020 10:41 am |
|
|
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: 19504
|
|
Posted: Sat Mar 21, 2020 12:55 pm |
|
|
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
|
|
Posted: Mon Mar 23, 2020 5:54 am |
|
|
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: 19504
|
|
Posted: Mon Mar 23, 2020 8:45 am |
|
|
Yes the first time I met this I spent the day performing 'wall, head impact
technology testing'....
Glad I could point to the problem. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon Mar 23, 2020 9:14 am |
|
|
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..... |
|
|
|