View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
RTCC and Alarm |
Posted: Sun Aug 05, 2018 10:52 pm |
|
|
Using PIC18F67K22
Compiler Version: 5.080
Using External 32KHz clock to run the RTCC.
The RTCC is running and keeping good time.
I searched CCS examples but I see the RTC example only does time/date no alarms.
I also noticed there are very few message about RTCC and Alarms.
This is my question: Does the RTCC Alarm really work ?
Thanks.
Info: not code.
I will post code after I call CCS and ask if a an example for RTCC and Alarms is available.
The Alarm is not working as I expected.
Here is output of the problem.
Start Time: 18/08/03 23:59:55 dow set to 05
Alarm Time Set to: 18/08/04 00:01:25 Alarm dow 06
Current Time: 05 18/08/03 23:59:55
Current Time: 05 18/08/03 23:59:56
Current Time: 05 18/08/03 23:59:57
Current Time: 05 18/08/03 23:59:58
Current Time: 05 18/08/03 23:59:59
Current Time: 06 18/08/04 00:00:00 // clock rolls over to next day
Current Time: 06 18/08/04 00:00:01
These current times removed to keep post small.
Current Time: 06 18/08/04 00:00:24
Current Time: 06 18/08/04 00:00:25
Alarm Time:06 18/08/04/ 00:00:25
Something wrong! Alarm at 25 seconds ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Aug 06, 2018 12:45 am |
|
|
You are going to need to show us at least your lines setting up the alarm and it's time. Remember if you want it to alarm at a particular time to the second it needs to be set to use RTC_ALARM_SECONDS. I've used them in the past on another chip and they did work. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
Re: RTCC and Alarm |
Posted: Mon Aug 06, 2018 11:32 am |
|
|
soonc wrote: | Start Time: 18/08/03 23:59:55 dow set to 05
Alarm Time Set to: 18/08/04 00:01:25 Alarm dow 06
Current Time: 06 18/08/04 00:00:24
Current Time: 06 18/08/04 00:00:25
Alarm Time:06 18/08/04/ 00:00:25
Something wrong! Alarm at 25 seconds ! |
Sounds like it's a zero reference being confused with a non-zero reference. You set the alarm to 1:25 and it goes off at 0:25. So is the clock referring to or calling the zeroeth minute the "first minute" or is your alarm setting routine doing that? |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
This is how it's done |
Posted: Mon Aug 06, 2018 1:41 pm |
|
|
Thanks Ttelmah and newguy,
I called CCS. There is no example for using RTCC and Alarms.
CCS did kindly explain how to use the MASK....
For a single alarm (not sure about repeat alarms I have not tested) set the highest alarm mask and it works for all values below that;
Code: |
For PIC18F67K22 I had to enable both Timer 1 and 3 to use the SOSC.
setup_timer_1( T1_ENABLE_SOSC | T1_EXTERNAL | T1_DIV_BY_1); // driven by External 32Khz Oscillator.
setup_timer_3( T3_ENABLE_SOSC | T3_EXTERNAL | T3_DIV_BY_1);// Can't use Sync to External if clk comes from 32KHz on PIN_B5
////////////////////////////////////////////////////////////////////////////
// RTC
setup_rtc(RTC_ENABLE, 0x00);
setup_rtc_alarm(RTC_ALARM_ENABLE | RTC_CHIME_DISABLE, RTC_ALARM_YEAR, 0x00);
|
Only use the Highest Mask then everything below that must match.
I set the Alarm mask for YEAR.... now the alarm will work for any time/date < than 1 year. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Tue Aug 07, 2018 5:24 am |
|
|
Glad they got back to you so fast!
Iwas curious about RTCC and downloaded the datasheet. After several reads and thinking I finally figured it out.
This.. from section 18.3.1....
The interval selection of the alarm is configured
through the ALRMCFG bits (AMASK<3:0>); see
Figure 18-5. These bits determine which, and how
many, digits of the alarm must match the clock value for
the alarm to occur
It's the last sentence that's important ! In the figure above it, it shows highlighted in white, the effect of the alarm 'mask' vs which digits. In the case of selecting the 'year' mask, you need ALL the time digits to be the same as your 'Alarm Time Set' data.
Probably 99% of the programmers will do what you've done, select 'year' and compare the full time for events that have to happen on a specific day and time of the year. However if you're doing a simple On at 7AM ,Off at 9PM function, you'd use the 'every day' mask,comparing HH:MM:SS. |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
|
Posted: Wed Aug 08, 2018 8:37 pm |
|
|
temtronic wrote: | Glad they got back to you so fast!
Iwas curious about RTCC and downloaded the datasheet. After several reads and thinking I finally figured it out.
This.. from section 18.3.1....
The interval selection of the alarm is configured
through the ALRMCFG bits (AMASK<3:0>); see
Figure 18-5. These bits determine which, and how
many, digits of the alarm must match the clock value for
the alarm to occur
It's the last sentence that's important ! In the figure above it, it shows highlighted in white, the effect of the alarm 'mask' vs which digits. In the case of selecting the 'year' mask, you need ALL the time digits to be the same as your 'Alarm Time Set' data.
Probably 99% of the programmers will do what you've done, select 'year' and compare the full time for events that have to happen on a specific day and time of the year. However if you're doing a simple On at 7AM ,Off at 9PM function, you'd use the 'every day' mask,comparing HH:MM:SS. |
You make a valid point, and no doubt there are other reasons for using the MASK the way you pointed out. It appears to be common for RTC... I'm also using a Philip RTC chip that does it almost the same way.
However: As speed is not an issue for my code my time functions just use the entire thing in a union/struct... Seconds through Year and the code is easier to understand rather than mucking with different settings for partial values.
Thanks for your input. |
|
|
|