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 CCS Technical Support

RTCC and Alarm

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

RTCC and Alarm
PostPosted: Sun Aug 05, 2018 10:52 pm     Reply with quote

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: 19480

View user's profile Send private message

PostPosted: Mon Aug 06, 2018 12:45 am     Reply with quote

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: 1907

View user's profile Send private message

Re: RTCC and Alarm
PostPosted: Mon Aug 06, 2018 11:32 am     Reply with quote

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

View user's profile Send private message

This is how it's done
PostPosted: Mon Aug 06, 2018 1:41 pm     Reply with quote

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: 9216
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 07, 2018 5:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 08, 2018 8:37 pm     Reply with quote

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.
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