View previous topic :: View next topic |
Author |
Message |
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Setting up RTC Interrupt |
Posted: Tue Aug 09, 2022 4:56 am |
|
|
Hi All,
I am new to CCS. So far, I have managed to move most codes to CCS. However stuck at one point whereby my RTC Alarm Interrupt does not work in CCS.
My fuses are set to use the internal 31KHz crystal. I do not need accurate alarm so I can afford to do this.
Then the code for setting up interrupt is as below:-
Code: | rtc_time_t ALARM_SETTINGS;
{
setup_rtc(RTC_ENABLE,0x00); //Enable RTC with no calibration.
setup_rtc_alarm (RTC_ALARM_DISABLE|RTC_CHIME_DISABLE, RTC_ALARM_WEEK, 0); // Weekly Alarm and No Repeat. Alarm Disabled
ALRMVAL_WWHH = 0x00; // These values will be calculated in my code depending on entries. However to get it going, I have set it up as 3 secs.
ALRMVAL_MMSS = 0x0003;
ALARM_SETTINGS.tm_year = 0x14;
ALARM_SETTINGS.tm_mon = 0x01;
ALARM_SETTINGS.tm_mday = 0x01;
ALARM_SETTINGS.tm_wday = ALARM_WEEK(ALRMVAL_WWHH);
ALARM_SETTINGS.tm_hour = ALARM_HOURS(ALRMVAL_WWHH);
ALARM_SETTINGS.tm_min = ALARM_MINS(ALRMVAL_MMSS);
ALARM_SETTINGS.tm_sec = ALARM_SECS(ALRMVAL_MMSS);
rtc_alarm_write(&ALARM_SETTINGS);
setup_rtc_alarm (RTC_ALARM_ENABLE|RTC_CHIME_DISABLE, RTC_ALARM_WEEK, 0); // Weekly Alarm and No Repeat. Alarm Disabled
enable_interrupts (INT_RTC);
}
The interrupt routine is written under:-
#INT_RTC
void RTC_isr (void)
{
}
|
I am using PIC18F66K22. Any thoughts would be appreciated. _________________ MVadukul |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Aug 09, 2022 5:53 am |
|
|
The chip does _not_ have an "internal 31KHz crystal". It has a relatively
poor internal 31K oscillator, but this is not even remotely good enough
really for an RTC.
However assuming you have got the RTC to work with the internal
oscillator, the alarm is quite non intuitive. The mask controlling how it
triggers takes a lot of getting your head round. Have a look at this
thread and in particular Jay's comment on this.
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=57354&highlight=setuprtc
[/url]
I suspect this is your problem. |
|
|
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Setting up RTC Interrupt |
Posted: Tue Aug 09, 2022 6:31 am |
|
|
I should have used the term Internal Oscillator for RTCC.
I can't tell whether my RTCC module is working or not in CCS as I am using the pins on the board, which could output the RTCC pulse.
I have run RTCC module and RTC alarm interrupt in the MPLAB, so surely it works. Its just that now i am using CCS, and but do not know how to adjust the ALRMPTR values and the operation. _________________ MVadukul |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Aug 09, 2022 9:45 am |
|
|
If you read the manual entry for the RTC, it says it _requires_ an external
32767Hz crystal. I have never looked at trying to run it from the internal
oscillator so cannot say if this is possible. Suspect it is not.
The way to test is simple start it up, read the time, Delay for a few
seconds, and read the time again. If it has changed, you have a running
RTC. You need to test this before trying to use alarms. |
|
|
mayur.k.vadukul
Joined: 07 Jul 2022 Posts: 40
|
Setting up RTC Interrupt |
Posted: Tue Aug 09, 2022 9:49 am |
|
|
I now got it going.
The issue was the way RTC Settings were written in the code.
It is possible to Run RTCC module with internal oscillator. It is not accurate. I don't need accuracy so it works to the satisfactory level.
It works the worst when running in sleep mode and with low current settings. i.e. unreliable to the level whereby it works literally double the time than the set duration. _________________ MVadukul |
|
|
|